2

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.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
sylsau
  • 413
  • 9
  • 19

2 Answers2

2

Some points in providing several layouts

  • Dont distinguish resource folders according to specific devices. The less folders you make, more the better...
  • Compare devices with their resolutions too when comparing with their sizes(One e.g is Nexus 7. Nexus 7 have a resolution of 1280 * 800 and other similar 7 inch tablets like Samsung Galaxy Tab have resolution of 1024 * 600).

The better practice is to put the following drawables

// for Phones
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi

//for 7 inch tablets
drawable-large-mdpi
drawable-large-hdpi(for Nexus 7)

// for 10 inch tablets
drawable-xlarge-mdpi

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 are mdpi devices and the drawable qualifier can change. (From my own experience, first put a folder drawable-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

  • Only added in API Level 13. So can't support earlier devices.
  • Because of its high precedence in qualifier list, we can't give other layouts starting with lower precedence qualifiers. Because Android always take higher precedence attributes first.
Renjith
  • 5,783
  • 9
  • 31
  • 42
  • I am having an issue implementing this in an application that should run on mdpi devices such as the Galaxy Tab 7 (the first one, 1024x600) and the Nexus 7. Both take resources from hdpi (the resource folder with that modifier, e.g. values-hdpi) when the Galaxy Tab 7 should take them from mdpi. We still have the manual change solution selecting different layouts based on runtime screen metrics. – DNax Sep 18 '13 at 21:13
  • Following some guidelines from http://android-developers.blogspot.com.ar/2012/07/getting-your-app-ready-for-jelly-bean.html that can be solved using the -tvdpi qualifier. – DNax Sep 19 '13 at 17:59
  • @RKN: Actually, the Nexus 7 is a *tvdpi* device. If it chooses an hdpi folder is because hdpi it's the nearest density – Jose_GD Nov 04 '13 at 17:59
  • It is worth pointing out that 7in tables are would be matched by drawable-large and 10in tables drawable-xlarge adding the dpi isn't necessary if you just want to target tablets. – Stefan Rusek Nov 10 '13 at 04:17
0

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.

Renascienza
  • 1,647
  • 1
  • 13
  • 16