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 ...
随机推荐
- Python tools used for file name devision
今天因为工作的缘故,需要用Python写一个能够完全分解文件名的小程序. import os #path = os.path.abspath('.') def split_fully(name): p ...
- tableviewcell 点击 设置
table?.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) //设置cell 下边线 位置 table?.se ...
- 【IE6的疯狂之十】父级使用padding后子元素绝对定位的BUG
在前端开发中,经常会用到css的position:absolute来使层浮动,前通过left,top,right等属性来对层进行定位,但ie6对left,top,right等属性的解释和ie7,ie8 ...
- AJAX应用的五个步骤
1.建立xmlHttpRequest对象 if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); if(xmlHttp.ov ...
- MyBatis 3 与 Spring 4 整合关键
MyBatis 3 与 Spring 4 整合关键 MyBatis与Spring整合,首先需要一个Spring数据源.其次有两个关键,配置sqlSessionFactory时需要配置扫描sql映射xm ...
- 使用 Git 报错 error: src refspec master matches more than one.
今天在使用 Git push 代码时遇到一个报错: error: src refspec master matches more than one. error: failed to push som ...
- Process Explorer(增强任务管理器) V16.05 免费绿色版
软件名称: Process Explorer(增强任务管理器)软件语言: 中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 1.2MB图片预 ...
- Linux_jdk
先查看下 yum list java* yum install java-1.7.0-openjdk* -y 环境变量应该是会自动配置的 或者手动配置编辑/etc/profile #vi /etc/p ...
- redis12--常用API
上一篇总结我们使用我们本地的Eclipse中创建的jedis工程,链接到了我们处于VMware虚拟机上的Linux系统上的Redis服务,我们接下来讲一下jedis的一些常用的API.(1)jedis ...
- channel bonding
一.什么是bondingLinux bonding驱动提供了一个把多个网络接口设备捆绑为单个的网络接口设置来使用,用于网络负载均衡及网络冗余二.bonding应用方向1.网络负载均衡对于bonding ...