android资源文件的选取
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资源文件的选取的更多相关文章
- Android资源文件简介
		
Android资源文件简介 1. Android应用资源的作用 (1) Android项目中文件分类 在Android工程中, 文件主要分为下面几类 : 界面布局文件, Java src源文件, 资源 ...
 - 【转】关于Android资源文件中出现百分号的问题
		
关于Android资源文件中出现百分号的问题 分类: Android JAVA2014-08-01 16:53 1345人阅读 评论(0) 收藏 举报 ANDROID格式化资源文件 目录(?)[+ ...
 - ANDROID资源文件【转】
		
1. 资源包括:文本字符串.图像和图标.音频文件.视频和其他应用程序使用的组件. 2. 在Android工程中,Android资源文件是同Java类文件分开存储的,大多数常见的资源类型存储在XML ...
 - 【Android 应用开发】Android资源文件 - 使用资源存储字符串 颜色 尺寸 整型 布尔值 数组
		
. 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/19913755 . 一. Android资源文件简介 1 ...
 - Android 资源文件命名与使用
		
[推荐]资源文件需带模块前缀 [推荐]layout 文件的命名方式 Activity 的 layout 以 module_activity 开头 Fragment 的 layout 以 module_ ...
 - Android资源文件 - 使用资源存储字符串 颜色 尺寸 整型 布尔值 数组
		
一. Android资源文件简介 1. Android应用资源的作用 (1) Android项目中文件分类 在Android工程中, 文件主要分为下面几类 : 界面布局文件, Java src源文件, ...
 - Android资源文件说明
		
一. Android资源文件简介 1. Android应用资源的作用 (1) Android项目中文件分类 在Android工程中, 文件主要分为下面几类 : 界面布局文件, Java src源文件, ...
 - android 资源文件
		
系统文档:http://developer.android.com/guide/topics/resources/available-resources.html 1. 系统下资源文件夹的名字是固定的 ...
 - [置顶] Android资源文件分析
		
1)修改开机默认壁纸 Android开机默认资源文件为:frameworks/base/core/res/res/values/config.xml 我们找到wallpaper行: <strin ...
 
随机推荐
- Android平台 视频编辑的高级版本
			
基本覆盖了秒拍,美拍,快手等视频编辑的大部分功能. 增加了44种滤镜,基本覆盖市面上大部分APP中的滤镜效果. 可以实现视频和视频, 视频和图片,视频和您的UI界面叠加. 在叠加的过程中:支持任意时间 ...
 - Java 并发 线程属性
			
Java 并发 线程属性 @author ixenos 线程优先级 1.每当线程调度器有机会选择新线程时,首先选择具有较高优先级的线程 2.默认情况下,一个线程继承它的父线程的优先级 当在一个运行的线 ...
 - 杭电OJ--自行车计速器
			
Biker's Trip Odometer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
 - Oracle新实例创建
			
http://blog.itpub.net/29519108/viewspace-1443918/ 刚开始创建时,千万别点容器数据库,不然后面新建用户时,用户名前得加C##. 常用命令: sqlplu ...
 - springmvc+maven
			
http://blog.csdn.net/zht666/article/details/8673609/
 - UltraISO PE(软碟通) V9.5.5.2960 官方中文版
			
软件名称: UltraISO PE(软碟通)软件语言: 简体中文授权方式: 免费试用运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 1.9MB图片预览: 软件简介 ...
 - SQLServer中的变量:局部变量,全局变量
			
SQLServer中的全局变量 变量 Transact-SQL语言中有两种形式的变量,一种是用户自己定义的局部变量,另外一种是系统提供的全局变量.局部变量 局部变量是一个能够拥有特定数据类型的对象 ...
 - 进程管理利器supervisor
			
supervisor安装 方法一 1:用管理员安装python-setuptools suse zypper in python-setuptools centos yum install pytho ...
 - MEAN全栈开发实践
 - 安卓Activity、service是否处于同一进程
			
Activity与Service是否处于同一进程? 1)默认情况下(不写android:process的时候),此时同一个应用程序的所有组建位于同一进程里,Activity与service也处于同 ...