屏幕适配一直是一个让人头疼的问题,论坛上讨论这个问题的最后也一般没有什么结果
有的提出使用RelativeLayout来进行相对位置的调整,也有的提出为每一个屏幕写出一套Layout来进行适配不同分辨率的屏幕。
我一直比较倾向使用RelativeLayout来进行编码,这样以后的代码维护量是比较少的,但是一些深度UI定制的程序使用RelativeLayout来进行的话也是行不通的,目前我们项目使用的Layout有上百个,所以没有办法全部使用RelativeLayout来进行处理,而且属于深度UI定制,所以只能通过制作不同的Values的dimens来进行处理了。
文件夹命名可以参考上边两个帖子,不过我还是将规则贴出来,便于大家参考。
优先级按照从上到下的方式查找。
Qualifier | Values | Description |
MCC and MNC | Examples: mcc310 mcc310-mnc004 mcc208-mnc00 etc. |
The mobile country code (MCC), optionally followed by mobile network code (MNC) from the SIM card in the device. For example, mcc310 is U.S. on any carrier, mcc310-mnc004 is U.S. on Verizon, and mcc208-mnc00 is France on Orange. If the device uses a radio connection (GSM phone), the MCC comes from the SIM, and the MNC comes from the network to which the device is connected. You can also use the MCC alone (for example, to include country-specific legalresources in your application). If you need to specify based on the language only, then use thelanguage and region qualifier instead (discussed next). If you decide to use the MCC andMNC qualifier, you should do so with care and test that it works as expected. Also see the configuration fields mcc, and mnc, which indicate the current mobile country codeand mobile network code, respectively. |
Language and region | Examples: en fr en-rUS fr-rFR fr-rCA etc. |
The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r"). The codes are not case-sensitive; the r prefix is used to distinguish the region portion. You cannot specify a region alone. This can change during the lifeof your application if the user changes his or her language in the system settings. See Handling Runtime Changes for information abouthow this can affect your application during runtime. See Localization for a complete guide to localizingyour application for other languages. Also see the locale configuration field, whichindicates the current locale. |
Screen size | small normal large xlarge |
See Supporting MultipleScreens for more information. Also see the screenLayout configuration field,which indicates whether the screen is small, normal,or large. |
Screen aspect | long notlong |
|
Screen orientation | port land |
|
Dock mode | car desk |
|
Night mode | night notnight |
This can change during the life of your application if night mode is left inauto mode (default), in which case the mode changes based on the time of day. You can enableor disable this mode using UiModeManager. See Handling Runtime Changes for information about how this affects yourapplication during runtime. |
Screen pixel density (dpi) | ldpi mdpi hdpi xhdpi nodpi |
There is thus a 3:4:6 scaling ratio between the three densities, so a 9x9 bitmap in ldpi is 12x12 in mdpi and 18x18 in hdpi. When Android selects which resource files to use, it handles screen density differently than the other qualifiers. In step 1 of How Android finds the best matching directory (below), screen density is always considered to be a match. In step 4, if the qualifier being considered is screen density, Android selects the best final match at that point, without any need to move on to step 5. See Supporting MultipleScreens for more information about how to handle screen sizes and how Android might scaleyour bitmaps. |
Touchscreen type | notouch stylus finger |
|
Keyboard availability | keysexposed keyssoft |
This can change during the life of your application if the user opens a hardwarekeyboard. See Handling Runtime Changes for information about howthis affects your application during runtime. Also see the configuration fields hardKeyboardHidden and keyboardHidden, which indicate the visibility of a hardwarekeyboard and and the visibility of any kind of keyboard (including software), respectively. |
Primary text input method | nokeys qwerty 12key |
|
Navigation key availability | navexposed navhidden |
Also see the navigationHidden configurationfield, which indicates whether navigation keys are hidden. |
Primary non-touch navigation method | nonav dpad trackball wheel |
|
System Version (API Level) | Examples: v3 v4 v7 etc. |
The API Level supported by the device. For example, v1 for API Level1 (devices with Android 1.0 or higher) and v4 for API Level 4 (devices with Android1.6 or higher). See the Android API Levels document for more informationabout these values.
Caution: Android 1.5 and 1.6 only match resourceswith this qualifier when it exactly matches the system version. See the section below about Known Issues for more information.
|
查找最匹配的资源。
How Android Finds the Best-matching ResourceWhen you request a resource for which you provide alternatives, Android selects whichalternative resource to use at runtime, depending on the current device configuration. Todemonstrate how Android selects an alternative resource, assume the following drawable directorieseach contain different versions of the same images:
drawable/drawable-en/drawable-fr-rCA/drawable-en-port/drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/And assume the following is the device configuration:
Screen orientation = port
Screen pixel density = hdpi
Touchscreen type = notouch
Primary text input method = 12key
By comparing the device configuration to the available alternative resources, Android selectsdrawables from drawable-en-port. It arrives at this decision using the following logic:
- Eliminate resource files that contradict the device configuration. The drawable-fr-rCA/ directory is eliminated, because itcontradicts the en-GB locale.
drawable/drawable-en/drawable-fr-rCA/drawable-en-port/drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/Exception: Screen pixel density is the one qualifier that is noteliminated due to a contradiction. Even though the screen density of the device is hdpi,drawable-port-ldpi/ is not eliminated because every screen density isconsidered to be a match at this point. More information is available in the Supporting MultipleScreens document. - Pick the (next) highest-precedence qualifier in the list (table 2).(Start with MCC, then move down.)
- Do any of the resource directories include this qualifier?
- If No, return to step 2 and look at the next qualifier. (In the example, the answer is "no" until the language qualifier is reached.)
- If Yes, continue to step 4.
- Eliminate resource directories that do not include this qualifier. In the example, the systemeliminates all the directories that do not include a language qualifier:
drawable/drawable-en/drawable-en-port/drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/Exception: If the qualifier in question is screen pixel density,Android selects the option that most closely matches the device screen density.In general, Android prefers scaling down a larger original image to scaling up a smalleroriginal image. See Supporting MultipleScreens. - Go back and repeat steps 2, 3, and 4 until only one directory remains. In the example, screenorientation is the next qualifier for which there are any matches.So, resources that do not specify a screen orientation are eliminated:drawable-en/drawable-en-port/drawable-en-notouch-12key/The remaining directory is drawable-en-port.
Though this procedure is executed for each resource requested, the system further optimizessome aspects. One such optimization is that once the device configuration is known, it mighteliminate alternative resources that can never match. For example, if the configurationlanguage is English ("en"), then any resource directory that has a language qualifier set tosomething other than English is never included in the pool of resources checked (though aresource directory without the language qualifier is still included).
To learn more about how to use resources in your application, continue to Accessing Resources.
屏幕分辨率:1024x600
density:1(160)
文件夹:values-mdpi-1024x600
屏幕分辨率:1024x600
density:1.5(240)
文件夹:values-hdpi-683x400 由1024/1.5 600/1.5得到,需要四舍五入。
屏幕分辨率:800x480
density:1(160)
文件夹:values-mdpi-800x480
屏幕分辨率:800x480
density:1.5(240)
文件夹:values-hdpi-533x320 由800/1.5 480/1.5得到,需要四舍五入。
以此类推
一般情况下需要创建出values 、values-mdpi 、 values-hdpi文件夹,以备在一些没有规定的尺寸屏幕上找不到资源的情况。
然后在里面使用不同的dimens文件,Layout中不要使用显示的数字,所有的尺寸定义全都援引dimens里面的内容。
这样能够保证深度UI定制的情况
0105补充
******************************
在工程的default.properties中如果split.density=false,则分辨率适配的时候文件夹命名不需要与scale相除
例
屏幕分辨率:800x480
density:1.5(240)
文件夹:values-hdpi-800x480
******************************
收藏自:http://www.eoeandroid.com/thread-53757-1-1.html
感谢:http://www.mangocd.com/