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 ...
随机推荐
- svn自动备份并上传到ftp
.建立bat文件 simpleBackup.bat,文件内容如下 @echo 正在备份版本库%1......@%SVN_HOME%bin\svnadmin hotcopy %1 %BACKUP_DIR ...
- linux命令之crontab详解
crontab命令: crontab -l : 显示定时任务列表 crontab -e: 编辑定时任务 crontab -r : 删除所有定时任务 基本格式 : * * * * * command ...
- 2017中国数据库技术大会(DTCC)又要来啦!期待~~
2017第八届中国数据库技术大会(DTCC2017)将于2017年5月11-13日如约而至.2017中国数据库技术大会(DTCC)以"数据驱动•价值发现"为主题,汇集来自互联网.电 ...
- redis介绍。
1. Redis是什么 这个问题的结果影响了我们怎么用Redis.如果你认为Redis是一个key value store, 那可能会用它来代替MySQL;如果认为它是一个可以持久化的cache, 可 ...
- Chapter 20_1 table库
table库是由一些辅助函数构成,把table作为数组来操作,所有的函数都忽略传入参数的那张表中的非数字键. 无论如何,若一个操作需要取表的长度,这个表必须是一个真序列,或是拥有__len元方法. 提 ...
- C#导出EXCEL的方法
/// using System; using System.Collections.Generic; using System.Text; using System.Data; using Syst ...
- Maven编译可执行jar
打包: 第一种情况:独立项目,且无第三方依赖包 这种情况下,我们需要maven的maven-jar-plugin插件来帮我们打包.请在项目pom.xml中的plugin配置处加入如下内 <plu ...
- 导航栏底部黑线隐藏 UINavigationBar hidden Bottom Line
3种方法: 1.大杀器 ,iOS 10.2 最新系统亲测无问题( 添加导航栏分类) https://github.com/samwize/UINavigationBar-Addition/ 2.io ...
- 《学习的艺术》 (The Art of Learning)
这是我本科期间读过的的一本,个人感觉很有价值的书.当时刚刚失恋,正在思考人生,看这本书的时候,收获很多. 划小圈 (Making Smaller Circles)
- 《JavaScript高级程序设计》读书笔记 ---RegExp 类型
ECMAScript 通过RegExp 类型来支持正则表达式.使用下面类似Perl 的语法,就可以创建一个正则表达式.var expression = / pattern / flags ; 其中的模 ...