当你要求为你提供替代的资源, 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。