I am trying to develop an efficient method of including resource qualifiers 
to appropriately select the layouts (and other resources really) for 
handsets, small tablets, and large tablets.  To properly support devices on 
both sides of Android 3.2, when smallest width was introduced, I had hoped 
to be able to create a hierarchy like so:

res/layout/
 + Default and handset-specific layouts
res/layout-sw600dp-large/
 + Small Tablet assets, where necessary
res/layout-sw720dp-xlarge/
 + Large Tablet assets, where necessary

However, constructing a simple test application in this manner reveals that 
the concept won't work.  All devices load the default resources, regardless 
of their OS version and display configuration.  The primary point of this 
method is to eliminate the duplication that would otherwise be required to 
place the "sw600dp" asset and "large" asset (which are the same) into 
separate directories.  Even aliasing a single layout into the two 
directories represents a duplication of code.  To support older devices, it 
would be nice to continue to use just the old qualifiers, but newer handset 
devices with larger screens are starting to creep into the "large" 
category, forcing the use of smallest width where available.

So my first question here is: I know my original idea does not work, but I 
want to know WHY it doesn't work??

In my mind, the old devices that don't understand the "sw" qualifier should 
just ignore its existence and the two directories should just look like 
"large" and "xlarge".  On the other side, with new devices, the "sw" 
qualifier should take precedence so the "large" and "xlarge" should become 
irrelevant.
As a result, the method with the least code duplication that I can come up 
with is as follows:

res/layout/
 + All layout assets, with tablet specific names in cases where necessary
res/values-sw600dp/
 + Aliases to apply small tablet layouts with the default name
res/values-large/
 + Same aliases to apply small tablet layouts with the default name
res/values-sw720dp/
 + Aliases to apply large tablet layouts with the default name
res/values-xlarge/
 + Same aliases to apply large tablet layouts with the default name

This reduces the duplication to at least one line in two places rather than 
copying an entire file.  Does anyone know of a method that works that would 
clean this up even further?

Thanks,

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to