Android app项目中,res是用来存放资源文件的,来看看这些文件的创建和选取规则:

系统启动一个apk后,生成UI的过程中,会根据不同的系统配置来匹配、选择相应的资源文件。

You should also provide alternative resources for specific device configurations, by grouping them in specially-named resource directories. At runtime, Android uses the appropriate resource based on the current configuration.

Almost every application should provide alternative resources to support specific device configurations.

每个APK都应该提供多个资源来支持指定的设备配置。

At runtime, Android detects the current device configuration and loads the appropriate resources for your application.

运行时,Android会检测目前的设备配置,并为你的应用加载合适的资源。

资源文件夹的名称形如: <resources_name>-<config_qualifier>
A、<resources_name> is the directory name of the corresponding default resources。 // 指示不同的资源类型

anim  ===  XML files that define tween animations.
color  ===  XML files that define a state list of colors.
drawable===  Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource subtypes: Bitmap files、Nine-Patches (re-sizable bitmaps)、State lists、Shapes、Animation drawables、Other drawables
layout ===  XML files that define a user interface layout.
menu  ===  XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu.
raw   ===  Arbitrary files to save in their raw form. To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
values ===  XML files that contain simple values, such as strings, integers, and colors. types: arrays.xml、colors.xml、values、dimens.xml、strings.xml、styles.xml
xml   ===  Arbitrary XML files that can be read at runtime by calling Resources.getXML(). Various XML configuration files must be saved here, such as a searchable configuration.

B、<qualifier> is a name that specifies an individual configuration for which these resources are to be used。
Android supports several configuration qualifiers and you can add multiple qualifiers to one directory name, by separating each qualifier with a dash.

常用的限定词有:
1. MCC and MNC: 如 mcc310-mnc004、mcc208-mnc00
indicate the current mobile country code and mobile network code, respectively.
2. Language and region: 如 fr、en-rUS
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").
3. Layout Direction: 两个值 ldrtl、ldltr
The layout direction of your application. ldrtl means "layout-direction-right-to-left". ldltr means "layout-direction-left-to-right" and is the default implicit value.
主要用于提供一些针对不同语言输出方向的布局。例如: layout-ldrtl/main.xml (Any "right-to-left" language, such as "ar" language for Arabic)
4. smallestWidth: sw<N>dp,如: sw600dp、sw720dp
指可被程序用户界面使用的屏幕可用空间的最小值(单位为dp)指可用屏幕两边中最短的那条边长。为了保证与应用程序兼容,设备的smallestWidth必须大于等于本属性值。(通常此值对应于布局layout所支持的“最小宽度”,而与屏幕当前的方向无关。)
5. Available width: w<N>dp,如:w720dp、w1024dp
Specifies a minimum available screen width, in dp units at which the resource should be used—defined by the <N> value.
该值会根据屏幕的方向而发生改变,如若,应用提供了多个不同值,系统会取用最接近实际值的那一项。
6. Available height: h<N>dp,如:h720dp、h1024dp
Specifies a minimum available screen height, in "dp" units at which the resource should be used—defined by the <N> value.
与前一项类似。
7. Screen size: 枚举值,small、normal、large、xlarge
small: is approximately 320x426 dp units.
normal: is approximately 320x470 dp units.
large: is approximately 480x640 dp units.
xlarge: is approximately 720x960 dp units.
8. Screen aspect: 枚举值,long、notlong
long: Long screens, such as WQVGA, WVGA, FWVGA
notlong: Not long screens, such as QVGA, HVGA, and VGA
9. Screen orientation: 枚举值,port、land
port: Device is in portrait orientation (vertical)
land: Device is in landscape orientation (horizontal)
10. UI mode: 枚举值,car、desk、television、appliance
car: Device is displaying in a car dock
desk: Device is displaying in a desk dock
television: Device is displaying on a television, providing a "ten foot" experience where its UI is on a large screen that the user is far away from, primarily oriented around DPAD or other non-pointer interaction
appliance: Device is serving as an appliance, with no display
11. Night mode: 枚举值,night、notnight
night: Night time
notnight: Day time
12. Screen pixel density (dpi):枚举值,ldpi、mdpi、hdpi、xhdpi、nodpi、tvdpi
ldpi: Low-density screens; approximately 120dpi.
mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
hdpi: High-density screens; approximately 240dpi.
xhdpi: Extra high-density screens; approximately 320dpi. Added in API Level 8
nodpi: This can be used for bitmap resources that you do not want to be scaled to match the device density.
tvdpi: Screens somewhere between mdpi and hdpi; approximately 213dpi.There is a 3:4:6:8 scaling ratio between the four primary densities (ignoring the tvdpi density). So, a 9x9 bitmap in ldpi is 12x12 in mdpi, 18x18 in hdpi and 24x24 in xhdpi.
13. Touchscreen type: 枚举值,notouch、finger
notouch: Device does not have a touchscreen.
finger: Device has a touchscreen that is intended to be used through direction interaction of the user's finger.
14. Keyboard availability: 枚举值,keysexposed、keyshidden、keyssoft
15. Primary text input method: 枚举值,nokeys、qwerty、12key
16. Navigation key availability: 枚举值, navexposed、navhidden
17. Primary non-touch navigation method: 枚举值,nonav、dpad、trackball、wheel
18. Platform Version (API level): 如 v3、v4
The API level supported by the device. For example, v1 for API level 1 (devices with Android 1.0 or higher) and v4 for API level 4 (devices with Android 1.6 or higher).

Android运行过程中,系统会根据当前的设备配置来选择合适的资源文件,基本原则如下:
1. 排除不合适的资源文件。
2. 按降序选取优先级最高的修饰词
3. 排除不含该修饰词的资源目录
4. 重复2、3,直到只包含一个目录

android资源文件的选取的更多相关文章

  1. Android资源文件简介

    Android资源文件简介 1. Android应用资源的作用 (1) Android项目中文件分类 在Android工程中, 文件主要分为下面几类 : 界面布局文件, Java src源文件, 资源 ...

  2. 【转】关于Android资源文件中出现百分号的问题

    关于Android资源文件中出现百分号的问题 分类: Android JAVA2014-08-01 16:53 1345人阅读 评论(0) 收藏 举报 ANDROID格式化资源文件   目录(?)[+ ...

  3. ANDROID资源文件【转】

    1.  资源包括:文本字符串.图像和图标.音频文件.视频和其他应用程序使用的组件. 2.  在Android工程中,Android资源文件是同Java类文件分开存储的,大多数常见的资源类型存储在XML ...

  4. 【Android 应用开发】Android资源文件 - 使用资源存储字符串 颜色 尺寸 整型 布尔值 数组

    . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/19913755 . 一. Android资源文件简介 1 ...

  5. Android 资源文件命名与使用

    [推荐]资源文件需带模块前缀 [推荐]layout 文件的命名方式 Activity 的 layout 以 module_activity 开头 Fragment 的 layout 以 module_ ...

  6. Android资源文件 - 使用资源存储字符串 颜色 尺寸 整型 布尔值 数组

    一. Android资源文件简介 1. Android应用资源的作用 (1) Android项目中文件分类 在Android工程中, 文件主要分为下面几类 : 界面布局文件, Java src源文件, ...

  7. Android资源文件说明

    一. Android资源文件简介 1. Android应用资源的作用 (1) Android项目中文件分类 在Android工程中, 文件主要分为下面几类 : 界面布局文件, Java src源文件, ...

  8. android 资源文件

    系统文档:http://developer.android.com/guide/topics/resources/available-resources.html 1. 系统下资源文件夹的名字是固定的 ...

  9. [置顶] Android资源文件分析

    1)修改开机默认壁纸 Android开机默认资源文件为:frameworks/base/core/res/res/values/config.xml 我们找到wallpaper行: <strin ...

随机推荐

  1. moodle其他代码

    , $sectionnum=false, $strictness=IGNORE_MISSING):给课程模块一个id,找出coursemoudle的描述 get_coursemodule_from_i ...

  2. RTMP直播应用与延时分析

    直播应用中,RTMP和HLS基本上可以覆盖所有客户端观看,HLS主要是延时比较大,RTMP主要优势在于延时低. 一.应用场景 低延时应用场景包括:  .  互动式直播:譬如2013年大行其道的美女主播 ...

  3. 前端tab页实例

    <div class="tabbable"> <ul class="nav nav-tabs padding-16"> <c:fo ...

  4. Form提交时隐藏Token验证

    前端声称一个Token @Html.AntiForgeryToken() 后台对Token进行验证 AntiForgery.Validate();

  5. UNIX基础--进程和守护进程

    进程和守护进程 Processes and Daemons 进程(Processes) FreeBSD 是一个多任务操作系统. 这就意味着好像一次可以运行一个以上的程序. 每个占用一定时间运行的程序就 ...

  6. LeetCode 395. Longest Substring with At Least K Repeating Characters C#

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  7. OOP in JS - Inheritance

    Summary You cause a class to inherit using ChildClassName.prototype = new ParentClass();. You need t ...

  8. IIS下无法访问.ini后缀文件

    环境: windows server 2003 R2.IIS6 问题: 无法访问网站下的.ini后缀的文件 解决办法: 添加ini文件的MIME映射,让IIS能下载扩展名是ini的文件 添加路径:相应 ...

  9. Linux文件挂载命令mount

    在linux系统中硬盘.u盘.光驱等其他设备都需要挂载后才能正常使用.下面是对挂载命令mount使用方法的一些总结. 文件挂载命令mountmount [-t 文件系统类型][-L卷标名][-o特殊选 ...

  10. C#字符串常见操作总结

    string类常用的方法和总结小记