Android如何找到最佳匹配资源

   当你要求为你提供替代的资源, Android的选择在运行时使用的替代资源,根据当前的设备配置。为了证明Android是如何选择的替代资源,假设每个都包含不同版本的相同图像的绘制如下的目录:

drawable/
drawable-en/
drawable-fr-rCA/
drawable-en-port/
drawable-en-notouch-12key/
drawable-port-ldpi/
drawable-port-notouch-12key/

 并且假设以下是设备配置:

Locale = en-GB 
Screen orientation = port 
Screen pixel density = hdpi 
Touchscreen type = notouch 
Primary text input method = 12key

 通过设备配置比较可用的替代资源, Android的选择资源可以从

drawable-en-port

  系统选择资源的逻辑是:

1、Eliminate resource files that contradict the device configuration(消除矛盾设备配置的资源文件)。 drawable-fr-rCA/ 因为语言不符淘汰了。

drawable/
drawable-en/
drawable-fr-rCA/
drawable-en-port/
drawable-en-notouch-12key/
drawable-port-ldpi/
drawable-port-notouch-12key/

2、Pick the (next) highest-precedence qualifier in the list (table 2). (Start with MCC, then move down.)

3、Do any of the resource directories include this qualifier(不要任何没有包含限定词的资源目录)?如果没有,返回步骤2 ,并期待在接下来的预选赛。 (在这个例子中,答案是“否” ,直到语言限定符就达到了。 )如果是,请继续执行步骤4 。

4、Eliminate resource directories that do not include this qualifier. In the example, the system eliminates 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/

5、Go back and repeat steps 2, 3, and 4 until only one directory remains. In the example, screen orientation is the next qualifier for which there are any matches(重复步骤2 ,3和4 ,直到只有一个目录仍然存在。在这个例子中,屏幕方向是下一个限定符)。所以,这不指定屏幕方向的资源被淘汰:

drawable-en/
drawable-en-port/
drawable-en-notouch-12key/

最后剩下:drawable-en-port。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值