Android multiple-screen qualifiers definitions

拥有回忆 提交于 2021-02-07 14:13:58

问题


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.


回答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+.




回答2:


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.



来源:https://stackoverflow.com/questions/10094174/android-multiple-screen-qualifiers-definitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!