I make an application with several layouts to target several devices like smartphones and tablets.
For the moment, I have the following folder to distinguish theses devices :
- res/layout # for normal devices like Samsung Galaxy Nexus, S III, ...
- res/layout-large # for tablet 7 inch on Android < 3.2
- res/layout-sw600dp # for tablet 7 inch
- res/layout-xlarge # for tablet 10 inch on Android < 3.2
- res/layout-sw720dp # for tablet 10 inch
The solution is good but I have a problem with old smartphones like HTC Desire that are still in Android 2.2 or 2.3.
Their screen size category is normal and density is hdpi so there is any difference with Samsung Galaxy Nexus for example in qualifiers in resources.
As version of Android is 2.2 or 2.3, I can't use new resources qualifiers for screen size. So, I don't know how I can target specifically these devices with qualifiers to have different layouts between Smartphones with screens that are 4 inch and more and with others that are screens with less than 4 inch.
Someone has any idea about a solution ?
Thanks by advance.
Sylvain.
Last (and valuable) hint:
Organize your layouts by SIZE, never DENSITY. Use dp and sp units, never pixels.
Organize your drawables by DENSITY, never SIZE. If you use 9-pacthes, provide alternative densities to mdpi, hdpi, xhdpi, xxhdpi too.
Some points in providing several layouts
The better practice is to put the following drawables
Giving support to tablets in Android is a hell job IMO. Because there are so many devices and each have their own resolutions and densities. You can't target all the devices.
Nexus 7 case: Even though Nexus 7 is a 7 inch tablet, it has resolution of 1280 * 800. So it's an
hdpi
device. But normal 7 inch devices have lower resolutions of 1024 * 600. So they aremdpi
devices and the drawable qualifier can change. (From my own experience, first put a folderdrawable-large-mdpi
for 7 inch devices and check it on Nexus 7. If there is no problem with images, you dont have to put another folder. Because if a particular folder is not present, Android will check for the nearest possible folder and optimize it for the device screen).Now the problem with giving
layout-sw<>dp
attribute are