码迷,mamicode.com
首页 > 其他好文 > 详细

res目录下的资源

时间:2016-10-01 17:28:28      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

 res文件夹里面的多个文件夹的各自介绍(来自网上的Android开发指南中文版内容):

目录Directory

资源类型Resource Types

res/anim/

XML文件,它们被编译进逐帧动画(frame by frame animation)或补间动画(tweened animation)对象

使用方法一般是 AnimationUtil.loadAnimation(R.anim.xxx)

res/drawable/

.png.9.png.jpg文件,它们被编译进以下的Drawable资源子类型中:

要获得这种类型的一个资源,可以使用Resource.getDrawable(id)

位图文件

9-patches(可变尺寸的位图)

为了获取资源类型,使用 mContext.getResources().getDrawable(R.drawable.imageId)

注意:放在这里的图像资源可能会被aapt工具自动地进行无损压缩优化。比如,一个真彩色但并不需要256色的PNG可能会被转换为一个带调色板的8PNG。这使得同等质量的图片占用更少的资源。所以我们得意识到这些放在该目录下的二进制图像在生成时可能会发生变化。如果你想读取一个图像位流并转换成一个位图(bitmap),请把图像文件放在res/raw/目录下这样可以避免被自动优化

res/layout/

被编译为屏幕布局(或屏幕的一部分)的XML文件。参见布局声明(Declaring Layout)

res/values/

可以被编译成很多种类型的资源的XML文件。

注意: 不像其他的res/文件夹,它可以保存任意数量的文件,这些文件保存了要创建资源的描述,而不是资源本身。XML元素类型控制这些资源应该放在R类的什么地方。

尽管这个文件夹里的文件可以任意命名,不过下面使一些比较典型的文件(文件命名的惯例是将元素类型包含在该名称之中):

      array.xml 定义数组

     colors.xml 定义color drawable颜色的字符串值(color string values)。使用Resource.getDrawable()Resources.getColor()分别获得这些资源。

     dimens.xml定义尺寸值(dimension value)。使用Resources.getDimension()获得这些资源。这个文件中的内容一般用在布局文件中 @dimens/xxx

      strings.xml定义字符串(string)值。使用Resources.getString()或者Resources.getText()获取这些资源getText()会保留在UI字符串上应用的丰富的文本样式。

      styles.xml 定义样式(style)对象。用在布局文件中

res/xml/

任意的XML文件,在运行时可以通过调用Resources.getXML()读取。

res/raw/

直接复制到设备中的任意文件。它们无需编译,添加到你的应用程序编译产生的压缩文件中。要使用这些资源,可以调用Resources.openRawResource(),参数是资源的ID,即R.raw.somefilename

补充一点, Resources的获取方式: context.getResources();
 
来源: <http://blog.csdn.net/chenzheng_java/article/details/6238437>

Here‘s a brief summary of each resource type:

Animation Resources
Define pre-determined animations.
Tween animations are saved in res/anim/ and accessed from the R.anim class.
Frame animations are saved in res/drawable/ and accessed from the R.drawable class.
Color State List Resource
Define a color resources that changes based on the View state.
Saved in res/color/ and accessed from the R.color class.
Drawable Resources
Define various graphics with bitmaps or XML.
Saved in res/drawable/ and accessed from the R.drawable class.
Layout Resource
Define the layout for your application UI.
Saved in res/layout/ and accessed from the R.layout class.
Menu Resource
Define the contents of your application menus.
Saved in res/menu/ and accessed from the R.menu class.
String Resources
Define strings, string arrays, and plurals (and include string formatting and styling).
Saved in res/values/ and accessed from the R.stringR.array, and R.plurals classes.
Style Resource
Define the look and format for UI elements.
Saved in res/values/ and accessed from the R.style class.
More Resource Types
Define values such as booleans, integers, dimensions, colors, and other arrays.
Saved in res/values/ but each accessed from unique R sub-classes (such as R.boolR.integerR.dimen, etc.).

 




res目录下的资源

标签:

原文地址:http://www.cnblogs.com/ywq-come/p/5925975.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!