5

I wanna create a layout compatible with a very large number of devices and screens. As I have been researching I found out that the most common screen resolutions are 249x320, 480x800, 600x1024, 720x1280 (and some other screens proportional to these).

Well, after reading the documentation I found out that there are two ways of doing it. Up to the 3.2 Android version I could use qualifiers for the layouts like "small, normal, large, xlarge" and combine them with "port" (portrait orientation) or "land" (landscape orientation".

Now, the second way (that seems to be the most recommended) is working only for Android 3.2 and later versions. You must specify the smallest width for which a layout must be used, no matter the screen orientation (???).

For the fact that you cannot specify the port or land qualifiers when using the second method, I prefer the first one. My question is: is the first method compatible with Android 3.2 and later versions? Must I use the first method for Android < 3.2 and the second for Android > 3.2? If so, I should create two projects, or maybe combine these two methods (create about 10 layout sizes, for the general-size qualifiers and for the specific minimum-width qualifiers). That would need more resources, I suppose.

Thanks and sorry for my bad language.

Piotr Niewinski
  • 1,298
  • 2
  • 15
  • 27
ali
  • 10,927
  • 20
  • 89
  • 138

2 Answers2

1

In Android you don't design your layouts based on pixels... you design them based on density independent pixels (dip or dp). These are device pixels scaled by the dots per inch screen density of your device. Android has 4 general screen density buckets, and you must provide drawables for each one under an appropriate folder (res/drawable-ldpi, res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi).

Other ways to make your layout compatible with a multitude of devices is to use 9png stretchable graphics, and use XML drawables that rely on dp for their dimensions.

Recommended reading for Android screen support:
http://developer.android.com/guide/practices/screens_support.html

As far as the smallest-width qualifier, you are missing the fact that the smallest width is specified in dp, not pixels. Check Table 2 in this section:
http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

The first method works on all devices, including Android 3.2+.

Theo
  • 5,963
  • 3
  • 38
  • 56
  • Thanks for the explanation. "res/drawable-??pi" is used to store images and style elements, like background definitions, etc. in order to keep the quality for each resolution (as I know). – ali Apr 10 '12 at 20:14
  • is it valid or required to give drawable-sw600dp-mdpi, drawable-sw600dp-mdpi and so on. – arjoan Sep 19 '12 at 16:02
  • 1
    @Arun: You can provide as many resource sets as you want, and use as many qualifier combinations as you need. On every device, the system will look for the best qualifier combination that most closely matches the device specs. – Theo Sep 20 '12 at 18:24
  • @Theo: When i tried with drawable-sw600dp-mdpi,drawable-sw720dp-hdpi,drawable-sw720dp-xhdpi , two tabs with densities mdpi and hdpi took the resource from drawable-sw720dp-xhdpi. I clueless about this behaviour. – arjoan Sep 21 '12 at 05:22
  • @Arun: Each device manufacturer enters the desired resolution, irrespective of actual dots per inch of the screen. If the device manufacturer has designated the device as an XHDPI device, then it will take its resources from XHDPI. How are you determining that your devices are MDPI and HDPI? – Theo Sep 21 '12 at 05:33
  • @Theo: When i tried with drawable-xlarge-mdpi,drawable-xlarge-hdpi,drawable-xlarge-xhdpi, the image was picked from drawable-xlarge-mdpi and drawable-xlarge-hdpi respectively – arjoan Sep 21 '12 at 05:43
  • @Arun: Please post a separate question and provide more detail so we can help you. – Theo Sep 21 '12 at 17:53
  • @Theo: http://stackoverflow.com/questions/12494670/using-smallest-width-configuration-qualifier – arjoan Sep 28 '12 at 03:59
  • @Theo:Pls check this also. Mark Murphy has raised a bug. http://code.google.com/p/android/issues/detail?id=37187 – arjoan Sep 28 '12 at 04:00
  • What is the image is a downloaded image. – Paul Okeke Jun 19 '15 at 13:54
0

May be the best way forward is to use both layout qualifiers : -

  1. res\layout-large
  2. res\layout-sw720dp

Setting the same layout in both directories using a layout alias.

aprofromindia
  • 1,111
  • 1
  • 13
  • 27