Android资源适配

不同的命名代表什么含义呢?详细见下表:

限定符Qualifier

Values

移动国家码MCC和移动网络码MNC

手机设备SIM卡上的移动国家码和移动网络码。比如mcc310-mnc004 (美国,Verizon品牌); mcc208-mnc00 (法国,Orange品牌); mcc234-mnc00 (英国,BT品牌). 
如果这个设备使用一个无线连接(GSM电话),则MCC来自SIM卡,而MNC来自该设备将要附着的网络。你有时会仅使用MCC,例如包含特定国家合法资源在您的应用程序中。如果您的应用程序指定了MCC/MNC组合的资源,这些资源仅在MCCMNC都匹配的时候才能使用。

语言和区域Languageand region

两个字母的ISO639-1语言码和ISO3166-1-alpha-2区域码 ("r"为前缀)。比如en-rUS,fr-rFR,es-rES.这个代码是大小写敏感的:语言码是小写字母,国家码是大写字母。你不能单独指定一个区域,但是你可以单独指定一个语言,比如en,fr, es, zh.

屏幕方向Screenorientation

纵向,横向,正方形(port,land, square

屏幕像素密度Screenpixel density

92dpi,108dpiAndroid选择使用哪个资源时,它对屏幕像素密度的处理和其它限定符不同。在文章后面描述的步骤1Android如何查找最匹配的目录中,屏幕密度总被认为是匹配的。在步骤4中,如果被考虑的限定符是屏幕密度,Android将选择在那个位置的最佳匹配,而无需继续步骤5

触摸屏类型Touchscreentype

非触摸式,触摸笔,手指(notouch,stylus, finger

键盘可用方式Whetherthe keyboard is available to the user

外在键盘,隐藏键盘,软键盘(keysexposed,keyshidden,keyssoft
如果你的应用程序有一个特定的资源只能通过软件盘使用,则使用keyssoft 值,如果没有keyssoft 资源可用(只有keysexposed 和 keyshidden)并且该设备显示了一个软键盘,那么系统将使用keysexposed 资源。

首选文本输入方法Primarytext input method

不支持按键,标准键盘,12(nokeys,qwerty, 12key)

首选非触摸式导航方法Primarynon-touchscreen
navigation method

不支持导航,滑板,跟踪球,滚轮(nonav,dpad, trackball, wheel)

屏幕分辨率Screendimensions

320x240,640x480更大的分辨率必须先被指定。

SDK版本SDKversion

设备支持的SDK版本,比如v3Android1.0SDKv11.1SDKv21.5SDKv3

小版本(Minorversion)

你目前还不能指定小版本,它总是被设置为0

文件夹命名的各个部分是有顺序的。即按上表从上到下的优先级别排列,如:

drawable-en-rUS-land-mdpi

drawable-en-rUS-port-160dpi-finger-qwerty-dpad-480x320/(US代表美式英语)

举个使用过程中的例子:

任意建一个android项目。看一下res目录结构:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

drawable-hdpi-finger与drawable-ldpi目录下面两张图片名称一样,但是图片不是同一张,分别是:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

layout、layout-finger、layout-land-finger下面的main.xml文件内容分别是:

layout/main.xml

[html]  view plain copy

  1. <?xml version\="1.0" encoding\="utf-8"?>  
  2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

  3. android:orientation=“vertical”

  4. android:layout_width=“fill_parent”

  5. android:layout_height=“fill_parent”

  6. >

  7. <ImageView

  8. android:layout_width=“wrap_content”

  9. android:layout_height=“wrap_content”

  10. android:src=“@drawable/icon”

  11. />

  12. <Button

  13. android:layout_width=“wrap_content”

  14. android:layout_height=“wrap_content”

  15. android:background=“@drawable/icon”

  16. />

  17. <TextView

  18. android:layout_width=“fill_parent”

  19. android:layout_height=“fill_parent”

  20. android:text=“layout only”/>

  21. </LinearLayout>

layout-finger/main.xml

[html]  view plain copy

  1. <?xml version\="1.0" encoding\="utf-8"?>  
  2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

  3. android:orientation=“vertical”

  4. android:layout_width=“fill_parent”

  5. android:layout_height=“fill_parent”

  6. >

  7. <ImageView

  8. android:layout_width=“wrap_content”

  9. android:layout_height=“wrap_content”

  10. android:src=“@drawable/icon”

  11. />

  12. <Button

  13. android:layout_width=“wrap_content”

  14. android:layout_height=“wrap_content”

  15. android:background=“@drawable/icon”

  16. />

  17. <TextView

  18. android:layout_width=“fill_parent”

  19. android:layout_height=“fill_parent”

  20. android:text=“layout-finger”/>

  21. </LinearLayout>

layout-land-finger/main.xml

[html]  view plain copy

  1. <?xml version\="1.0" encoding\="utf-8"?>  
  2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”

  3. android:orientation=“vertical”

  4. android:layout_width=“fill_parent”

  5. android:layout_height=“fill_parent”

  6. >

  7. <ImageView

  8. android:layout_width=“wrap_content”

  9. android:layout_height=“wrap_content”

  10. android:src=“@drawable/icon”

  11. />

  12. <Button

  13. android:layout_width=“wrap_content”

  14. android:layout_height=“wrap_content”

  15. android:background=“@drawable/icon”

  16. />

  17. <TextView

  18. android:layout_width=“fill_parent”

  19. android:layout_height=“fill_parent”

  20. android:text=“layout-land-finger”/>

  21. </LinearLayout>

  22. android:layout_width=“fill_parent”

  23. android:layout_height=“fill_parent”

  24. android:text=“layout-land-finger”/>

  25. </LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值