- 浏览: 35952 次
- 性别:
- 来自: 济南
最近访客 更多访客>>
文章分类
最新评论
-
accelater:
看了后有很大收获
自定义ContentProvider -
zzhui1988:
很好,很有用
android工程下的文件资源类型 -
sester9:
<div class="quote_title ...
android工程下的文件资源类型 -
sester9:
总结得非常好,学习了
android工程下的文件资源类型 -
xtulnx:
assets 里面的文件,像给webView之类用的时候,要用 ...
android工程下的文件资源类型
android工程下的文件资源类型
一个android工程中,有各种类型的资源文件,大致可以分为以下几种:
1、 颜色 #RGB #ARGB #RRGGBB #AARRGGBB
颜色资源应该位于<resourses></resourses>标签下
路径res/values/colors.xml 名字可以随意
定义<color name=”cname”>value</color>
使用 Resourse.getValues.getColor
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
</resources>
2、 字串
字串资源应该位于<resourses></resourses>标签下
路径res/values/strings.xml
定义<String name=”sname”>value</String>
使用 Resourse.getValues.getString
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, ResrouseTestActivity!</string>
<string name="app_name">ResrouseTest</string>
</resources>
3、 图片
图片资源一般使用png格式,使用其他格式的会出现各种问题,貌似不支持gif格式的图片,可是使用Movie来播放gif格式的图片
路径res/drawable
可以直接存放图片也可以是xml等配置文件(一般用于自定义组件)
使用 getDrawable
4、 图片的颜色
位于res/values/my_drawable.xml名字随意
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="solid_red">#FF0000</drawable>
</resources>
定义用于填充一个组件的颜色值,即给view设置背景色。用法和drawable下的图片一样,其实没多少意义,使用颜色定义就ok了,目前我是这样认为的,可能有更好的优点,不过我没发现罢了,嘿嘿,continue...
5、 单位资源
单位资源应该位于<resourses></resourses>标签下
路径res/values/dimen.xml 名字可以随意
使用和String、color类似
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dimen_name">2px</dimen>
<dimen name="dimen_px">5px</dimen>
<dimen name="dimen_pt">3pt</dimen>
<dimen name="dimen_dp">3dp</dimen>
</resources>
6、 Nine-patch(可以拉伸的小图片)
支持图片的拉伸
貌似就是所谓的png图片文件资源,图片在应用view的背景时,如果被设为background则会随view的大小变化做相应的拉伸和收缩,像ImageView这类设置src图片则不随view变化,按其自身大小显示部分或全部!
7、 菜单
菜单即可以从代码中实现也可以在资源文件中配置,这里就是要描述一下第二种
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/previous"
android:title="@string/previous"
android:enabled="false" android:icon="@android:drawable/ic_media_previous"/>
<item
android:id="@+id/play_pause"
android:title="@string/play"
android:icon="@android:drawable/ic_media_play"/>
<item
android:id="@+id/next"
android:title="@string/next"
android:icon="@android:drawable/ic_menu_next"/>
</menu>
8、 Layout布局
这个就是你经常看到的与用户交互的界面的xml文件,就是各个view的排列和嵌套,没什么好说的啦
9、 风格和主题、
风格主要是指view的显示风格 res/values/filename.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<resources>
<style name=”SpecialText” parent=”@style/Text”>
<item name=”android:textSize”>18sp</item>
<item name=”android:textColor”>#008</item>
</style>
</resources>
主题主要针对Activity等, 可以在Android Manifest中定义的<application>和<activity>元素将主题添加到整个程序或者某个 Activity,但是主题是不能应用在某一个单独的View里.风格可以自己定义也可以使用程序自带的或是继承已有的风格。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="windowFrame">@drawable/screen_frame</item>
<item name="windowBackground">@drawable/screen_background_white</item>
<item name="panelForegroundColor">#FF000000</item>
<item name="panelBackgroundColor">#FFFFFFFF</item>
<item name="panelTextColor">?panelForegroundColor</item>
<item name="panelTextSize">14</item>
<item name="menuItemTextColor">?panelTextColor</item>
<item name="menuItemTextSize">?panelTextSize</item>
</style>
</resources>
10、 动画
动画资源分为两种,一是实现图片的translate、scale、rotate、alpha四种变化。还可以设置动画的播放特性;另一种是帧动画,逐帧播放设置的资源
先说一下第一种
Res/anim/filename.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:interpolator="@android:anim/accelerate_interpolator"
android:fromXDelta="0" android:toXDelta="200" android:fromYDelta="0"
android:toYDelta="180" android:duration="2000" />
<scale android:interpolator="@android:anim/accelerate_interpolator"
android:fromXScale="1.0" android:toXScale="2.0" android:fromYScale="1.0"
android:toYScale="2.0" android:pivotX="150%" android:pivotY="150%"
android:duration="2000" />
<alpha android:fromAlpha="1.0" android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime" />
<rotate ....各个属性></rotate>
<Interpolator >可以使用其子类和属性定义动画的运行方式,先快后慢,先慢后快等</Interpolator>
</set>
具体参数的用法,大家可以自己查资料
下面是第二种资源
<animation-list xmlns:android=”http://schemas.android.com/apk/res/android”
android:oneshot=”true”>
<item android:drawable=”@drawable/rocket_thrust1″ android:duration=”200″ />
<item android:drawable=”@drawable/rocket_thrust2″ android:duration=”200″ />
<item android:drawable=”@drawable/rocket_thrust3″ android:duration=”200″ />
</animation-list>
<script src="/javascripts/tinymce/plugins/javaeye/langs/zh.js" type="text/javascript"></script>
rif;">1. 相关文件夹介绍 在Android项目文件夹里面,主要的资源文件是放在res文件夹里面的。assets文件夹是存放不进行编译加工的原生文件,即该文件夹里面的文件不会像xml,java文件被预编译,可以存放一些图片,html,js, css等文件。在后面会介绍如何读取assets文件夹的资源! res文件夹里面的多个文件夹的各自介绍(来自网上的Android开发指南中文版内容):
|
评论
<div class="quote_div">
<p> </p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">一个</span><span style="line-height: 21px;" lang="EN-US">android</span><span style="line-height: 21px;">工程中,有各种类型的资源文件,大致可以分为以下几种:</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">1、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">颜色</span><span style="line-height: 21px;" lang="EN-US"> #RGB #ARGB #RRGGBB #AARRGGBB</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">颜色资源应该位于</span><span style="line-height: 21px;" lang="EN-US"><resourses></resourses></span><span style="line-height: 21px;">标签下</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">路径</span><span style="line-height: 21px;" lang="EN-US">res/values/colors.xml </span><span style="line-height: 21px;">名字可以随意</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">定义</span><span style="line-height: 21px;" lang="EN-US"><color name=”cname”>value</color></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">使用</span><span style="line-height: 21px;" lang="EN-US"> Resourse.getValues.getColor</span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><?</span><span style="line-height: 21px;" lang="EN-US">xml</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">version</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"1.0"</span></em> <span style="line-height: 21px;">encoding</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"utf-8"</span></em><span style="line-height: 21px;">?></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">color</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"white"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">#FFFFFF</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">color</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">color</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"black"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">#000000</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">color</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"></</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">2、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">字串</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">字串资源应该位于</span><span style="line-height: 21px;" lang="EN-US"><resourses></resourses></span><span style="line-height: 21px;">标签下</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">路径</span><span style="line-height: 21px;" lang="EN-US">res/values/strings.xml</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">定义</span><span style="line-height: 21px;" lang="EN-US"><String<span style="line-height: 21px;"> </span>name=”sname”>value</String></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">使用</span><span style="line-height: 21px;" lang="EN-US"> Resourse.getValues.getString</span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><?</span><span style="line-height: 21px;" lang="EN-US">xml</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">version</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"1.0"</span></em> <span style="line-height: 21px;">encoding</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"utf-8"</span></em><span style="line-height: 21px;">?></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;"> </span></span><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">string</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"hello"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">Hello World, ResrouseTestActivity!</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">string</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;"> </span></span><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">string</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"app_name"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">ResrouseTest</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">string</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"></</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"> </span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">3、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">图片</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">图片资源一般使用</span><span style="line-height: 21px;" lang="EN-US">png</span><span style="line-height: 21px;">格式,使用其他格式的会出现各种问题,貌似不支持</span><span style="line-height: 21px;" lang="EN-US">gif</span><span style="line-height: 21px;">格式的图片,可是使用</span><span style="line-height: 21px;" lang="EN-US">Movie</span><span style="line-height: 21px;">来播放</span><span style="line-height: 21px;" lang="EN-US">gif</span><span style="line-height: 21px;">格式的图片</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">路径</span><span style="line-height: 21px;" lang="EN-US">res/drawable</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">可以直接存放图片也可以是</span><span style="line-height: 21px;" lang="EN-US">xml</span><span style="line-height: 21px;">等配置文件(一般用于自定义组件)</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">使用</span> <span style="line-height: 21px;" lang="EN-US">getDrawable</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"> </span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">4、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">图片的颜色</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">位于</span><span style="line-height: 21px;" lang="EN-US">res/values/my_drawable.xml</span><span style="line-height: 21px;">名字随意</span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;"> </span></span><span style="line-height: 21px;" lang="EN-US"><?</span><span style="line-height: 21px;" lang="EN-US">xml</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">version</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"1.0"</span></em> <span style="line-height: 21px;">encoding</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"utf-8"</span></em><span style="line-height: 21px;">?></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">drawable</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"solid_red"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">#FF0000</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">drawable</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"></</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">定义用于填充一个组件的颜色值,即给</span><span style="line-height: 21px;" lang="EN-US">view</span><span style="line-height: 21px;">设置背景色。用法和</span><span style="line-height: 21px;" lang="EN-US">drawable</span><span style="line-height: 21px;">下的图片一样,其实没多少意义,使用颜色定义就</span><span style="line-height: 21px;" lang="EN-US">ok</span><span style="line-height: 21px;">了,目前我是这样认为的,可能有更好的优点,不过我没发现罢了,嘿嘿,</span><span style="line-height: 21px;" lang="EN-US">continue...</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">5、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">单位资源</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">单位资源应该位于</span><span style="line-height: 21px;" lang="EN-US"><resourses></resourses></span><span style="line-height: 21px;">标签下</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">路径</span><span style="line-height: 21px;" lang="EN-US">res/values/dimen.xml </span><span style="line-height: 21px;">名字可以随意</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">使用和</span><span style="line-height: 21px;" lang="EN-US">String</span><span style="line-height: 21px;">、</span><span style="line-height: 21px;" lang="EN-US">color</span><span style="line-height: 21px;">类似</span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><?</span><span style="line-height: 21px;" lang="EN-US">xml</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">version</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"1.0"</span></em> <span style="line-height: 21px;">encoding</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"utf-8"</span></em><span style="line-height: 21px;">?></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">dimen</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"dimen_name"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">2px</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">dimen</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">dimen</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"dimen_px"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">5px</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">dimen</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">dimen</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"dimen_pt"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">3pt</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">dimen</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"><</span><span style="line-height: 21px;" lang="EN-US">dimen</span><span style="line-height: 21px;" lang="EN-US"> <span style="line-height: 21px;">name</span><span style="line-height: 21px;">=</span><em style="font-style: italic;"><span style="line-height: 21px;">"dimen_dp"</span></em><span style="line-height: 21px;">></span><span style="line-height: 21px;">3dp</span><span style="line-height: 21px;"></</span><span style="line-height: 21px;">dimen</span><span style="line-height: 21px;">></span></span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;" align="left"><span style="line-height: 21px;" lang="EN-US"></</span><span style="line-height: 21px;" lang="EN-US">resources</span><span style="line-height: 21px;" lang="EN-US">></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">6、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;" lang="EN-US">Nine-patch</span><span style="line-height: 21px;">(可以拉伸的小图片)</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">支持图片的拉伸</span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;"> </span></span><span style="line-height: 21px;">貌似就是所谓的</span><span style="line-height: 21px;" lang="EN-US">png</span><span style="line-height: 21px;">图片文件资源,图片在应用</span><span style="line-height: 21px;" lang="EN-US">view</span><span style="line-height: 21px;">的背景时,如果被设为</span><span style="line-height: 21px;" lang="EN-US">background</span><span style="line-height: 21px;">则会随</span><span style="line-height: 21px;" lang="EN-US">view</span><span style="line-height: 21px;">的大小变化做相应的拉伸和收缩,像</span><span style="line-height: 21px;" lang="EN-US">ImageView</span><span style="line-height: 21px;">这类设置</span><span style="line-height: 21px;" lang="EN-US">src</span><span style="line-height: 21px;">图片则不随</span><span style="line-height: 21px;" lang="EN-US">view</span><span style="line-height: 21px;">变化,按其自身大小显示部分或全部!</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">7、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">菜单</span></p>
<pre><span><span>菜单即可以从代码中实现也可以在资源文件中配置,这里就是要描述一下第二种</span></span></pre>
<pre><span><span lang="EN-US"><?xml version="1.0" encoding="utf-8"?></span></span></pre>
<pre><span><span lang="EN-US"><menu xmlns:android="http://schemas.android.com/apk/res/android"></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><item<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:id="@+id/previous"<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:title="@string/previous"<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:enabled="false"<span> </span>android:icon="@android:drawable/ic_media_previous"/></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><item<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:id="@+id/play_pause"<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:title="@string/play"<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:icon="@android:drawable/ic_media_play"/></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><item<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:id="@+id/next"<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:title="@string/next"<span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:icon="@android:drawable/ic_menu_next"/></span></span></pre>
<pre><span><span lang="EN-US"></menu></span></span></pre>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">8、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;" lang="EN-US">Layout</span><span style="line-height: 21px;">布局</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">这个就是你经常看到的与用户交互的界面的</span><span style="line-height: 21px;" lang="EN-US">xml</span><span style="line-height: 21px;">文件,就是各个</span><span style="line-height: 21px;" lang="EN-US">view</span><span style="line-height: 21px;">的排列和嵌套,没什么好说的啦</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">9、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">风格和主题、</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">风格主要是指</span><span style="line-height: 21px;" lang="EN-US">view</span><span style="line-height: 21px;">的显示风格</span><span style="line-height: 21px;" lang="EN-US"> res/values/filename.xml</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;"><span style="line-height: 21px;" lang="EN-US"><?xml version=”1.0″ encoding=”utf-8″?></span></span><span style="line-height: 21px;" lang="EN-US"><br><span style="line-height: 21px;"><resources></span><br><span style="line-height: 21px;"> <style name=”SpecialText” parent=”@style/Text”></span><br><span style="line-height: 21px;"> <item name=”android:textSize”>18sp</item></span><br><span style="line-height: 21px;"> <item name=”android:textColor”>#008</item></span><br><span style="line-height: 21px;"></style></span><br><span style="line-height: 21px;"></resources></span></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">主题主要针对</span><span style="line-height: 21px;" lang="EN-US">Activity</span><span style="line-height: 21px;">等</span><span style="line-height: 21px;" lang="EN-US">,</span><span style="line-height: 21px;" lang="EN-US"> </span><span style="line-height: 21px;"><span style="line-height: 21px;">可以在</span></span><span style="line-height: 21px;"><span style="line-height: 21px;" lang="EN-US">Android Manifest</span></span><span style="line-height: 21px;"><span style="line-height: 21px;">中定义的</span></span><span style="line-height: 21px;"><span style="line-height: 21px;" lang="EN-US"><application></span></span><span style="line-height: 21px;"><span style="line-height: 21px;">和</span></span><span style="line-height: 21px;"><span style="line-height: 21px;" lang="EN-US"><activity></span></span><span style="line-height: 21px;"><span style="line-height: 21px;">元素将主题添加到整个程序或者某个</span></span><span style="line-height: 21px;"><span style="line-height: 21px;" lang="EN-US"> Activity</span></span><span style="line-height: 21px;"><span style="line-height: 21px;">,但是主题是不能应用在某一个单独的</span></span><span style="line-height: 21px;"><span style="line-height: 21px;" lang="EN-US">View</span></span><span style="line-height: 21px;"><span style="line-height: 21px;">里</span></span><span style="line-height: 21px;"><span style="line-height: 21px;" lang="EN-US">.</span></span><span style="line-height: 21px;"><span style="line-height: 21px;">风格可以自己定义也可以使用程序自带的或是继承已有的风格。</span></span></p>
<pre><span><span lang="EN-US"><?xml version="1.0" encoding="utf-8"?></span></span></pre>
<pre><span><span lang="EN-US"><resources></span></span></pre>
<pre><span><span lang="EN-US"><style name="CustomTheme"></span></span></pre>
<pre><span><span lang="EN-US"><item name="android:windowNoTitle">true</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="windowFrame">@drawable/screen_frame</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="windowBackground">@drawable/screen_background_white</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="panelForegroundColor">#FF000000</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="panelBackgroundColor">#FFFFFFFF</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="panelTextColor">?panelForegroundColor</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="panelTextSize">14</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="menuItemTextColor">?panelTextColor</item></span></span></pre>
<pre><span><span lang="EN-US"><item name="menuItemTextSize">?panelTextSize</item></span></span></pre>
<pre><span><span lang="EN-US"></style></span></span></pre>
<pre><span><span lang="EN-US"></resources></span></span></pre>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"> </span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><span style="line-height: 21px;">10、<span style="line-height: 21px;"> </span></span></span><span style="line-height: 21px;">动画</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">动画资源分为两种,一是实现图片的</span><span style="line-height: 21px;" lang="EN-US">translate</span><span style="line-height: 21px;">、</span><span style="line-height: 21px;" lang="EN-US">scale</span><span style="line-height: 21px;">、</span><span style="line-height: 21px;" lang="EN-US">rotate</span><span style="line-height: 21px;">、</span><span style="line-height: 21px;" lang="EN-US">alpha</span><span style="line-height: 21px;">四种变化。还可以设置动画的播放特性;另一种是帧动画,逐帧播放设置的资源</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">先说一下第一种</span></p>
<pre><span><span lang="EN-US">Res/anim/filename.xml</span></span></pre>
<pre><span><span lang="EN-US"><set xmlns:android="http://schemas.android.com/apk/res/android"><span> </span></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><translate android:interpolator="@android:anim/accelerate_interpolator"</span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:fromXDelta="0" android:toXDelta="200" android:fromYDelta="0"</span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:toYDelta="180" android:duration="2000" /></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><scale android:interpolator="@android:anim/accelerate_interpolator"</span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:fromXScale="1.0" android:toXScale="2.0" android:fromYScale="1.0"</span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:toYScale="2.0" android:pivotX="150%" android:pivotY="150%"</span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:duration="2000" /></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><alpha android:fromAlpha="1.0" android:toAlpha="1.0"</span></span></pre>
<pre><span><span lang="EN-US"><span> </span>android:duration="@android:integer/config_mediumAnimTime" /></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><rotate ....</span></span><span><span>各个属性</span></span><span><span lang="EN-US">></rotate></span></span></pre>
<pre><span><span lang="EN-US"><span> </span><Interpolator ></span></span><span><span>可以使用其子类和属性定义动画的运行方式,先快后慢,先慢后快等</span></span><span><span lang="EN-US"></Interpolator></span></span></pre>
<pre><span><span lang="EN-US"></set><span> </span></span></span></pre>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">具体参数的用法,大家可以自己查资料</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">下面是第二种资源</span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"><animation-list xmlns:android=”http://schemas.android.com/apk/res/android”<br>android:oneshot=”true”><br><item android:drawable=”@drawable/rocket_thrust1″ android:duration=”200″ /><br><item android:drawable=”@drawable/rocket_thrust2″ android:duration=”200″ /><br><item android:drawable=”@drawable/rocket_thrust3″ android:duration=”200″ /><br></animation-list></span></p>
<p class="MsoListParagraph" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;" lang="EN-US"> </span></p>
<table border="0" cellspacing="0" cellpadding="0"><tbody><tr>
<td id="postmessage_2907" class="t_msgfont"><span style="color: #000000;"><span><script src="/javascripts/tinymce/plugins/javaeye/langs/zh.js" type="text/javascript"></script> rif;">1. 相关文件夹介绍 在Android项目文件夹里面,主要的资源文件是放在res文件夹里面的。assets文件夹是存放不进行编译加工的原生文件,即该文件夹里面的文件不会像xml,java文件被预编译,可以存放一些图片,html,js, css等文件。在后面会介绍如何读取assets文件夹的资源!<br> res文件夹里面的多个文件夹的各自介绍(来自网上的Android开发指南中文版内容):<br><table class="t_table" border="0" cellspacing="0"><tbody>
<tr>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><strong><span><span style="line-height: 21px;">目录</span></span></strong><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Directory</span></span></strong></p>
</td>
<td width="80%">
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><strong><span><span style="line-height: 21px;">资源类型</span></span></strong><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resource Types</span></span></strong></p>
</td>
</tr>
<tr>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">res/anim/</span></p>
</td>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">XML</span></span><span><span style="line-height: 21px;">文件,它们被编译进逐帧动画(</span></span><a style="text-decoration: none; color: #336699;" href="http://developer.android.com/guide/topics/resources/available-resources.html#animationdrawable" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">frame by frame animation</span></span></a><span><span style="line-height: 21px;">)或补间动画(</span></span><a style="text-decoration: none; color: #336699;" href="http://developer.android.com/guide/topics/resources/available-resources.html#tweenedanimation" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">tweened animation</span></span></a><span><span style="line-height: 21px;">)对象</span></span></p>
</td>
</tr>
<tr>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">res/drawable/</span></p>
</td>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">.png</span></span><span><span style="line-height: 21px;">、</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">.9.png</span></span><span><span style="line-height: 21px;">、</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">.jpg</span></span><span><span style="line-height: 21px;">文件,它们被编译进以下的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Drawable</span></span><span><span style="line-height: 21px;">资源子类型中:</span></span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">要获得这种类型的一个资源,可以使用</span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resource.getDrawable(<em style="font-style: italic;">id</em>)</span></span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/available-resources.html#imagefileresources" target="_blank"><span><span style="line-height: 21px;">位图文件</span></span></a></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/available-resources.html#ninepatch" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">9-patches</span></span><span><span style="line-height: 21px;">(可变尺寸的位图)</span></span></a></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span><span style="line-height: 21px;">为了获取资源类型,使用</span></span><span style="line-height: 21px;">mContext.getResources().getDrawable(R.drawable.imageId)</span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><strong><span><span style="line-height: 21px;">注意:</span></span></strong><span><span style="line-height: 21px;">放在这里的图像资源可能会被</span></span><a style="text-decoration: none; color: #336699;" href="http://www.cnblogs.com/tt_mc/admin/file:///D:/xfchen/ebook/android_dev_guide/developer.android.com/guide/developing/tools/aapt.html" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">aapt</span></span></a><span><span style="line-height: 21px;">工具自动地进行无损压缩优化。比如,一个真彩色但并不需要</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">256</span></span><span><span style="line-height: 21px;">色的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">PNG</span></span><span><span style="line-height: 21px;">可能会被转换为一个带调色板的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">8</span></span><span><span style="line-height: 21px;">位</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">PNG</span></span><span><span style="line-height: 21px;">。这使得同等质量的图片占用更少的资源。所以我们得意识到这些放在该目录下的二进制图像在生成时可能会发生变化。如果你想读取一个图像位流并转</span></span><span><span style="line-height: 21px;">换成一个位图</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">(bitmap)</span></span><span><span style="line-height: 21px;">,请把图像文件放在</span></span><span style="line-height: 21px;">res/raw/</span><span><span style="line-height: 21px;">目录下</span></span><span><span style="line-height: 21px;">,</span></span><span><span style="line-height: 21px;">这样可以避免被自动优化。</span></span></p>
<br>
</td>
</tr>
<tr>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">res/layout/</span></p>
</td>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span><span style="line-height: 21px;">被编译为屏幕布局(或屏幕的一部分)的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">XML</span></span><span><span style="line-height: 21px;">文件。</span></span><span><span style="line-height: 21px;">参见布局声明</span></span><a style="text-decoration: none; color: #336699;" href="http://www.cnblogs.com/tt_mc/admin/file:///G:/Docs/android_dev_guide/android_dev_guide/developer.android.com/guide/topics/ui/declaring-layout.html" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">(Declaring Layout)</span></span></a></p>
</td>
</tr>
<tr>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">res/values/</span></p>
</td>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span><span style="line-height: 21px;">可以被编译成很多种类型的资源的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">XML</span></span><span><span style="line-height: 21px;">文件。</span></span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><strong><span><span style="line-height: 21px;">注意</span></span></strong><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">:</span></span></strong><br><span><span style="line-height: 21px;">不像其他的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">res/</span></span><span><span style="line-height: 21px;">文件夹,它可以保存任意数量的文件,这些文件保存了要创建资源的描述,而不是资源本身。</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">XML</span></span><span><span style="line-height: 21px;">元素类型控制这些资源应该放在</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">R</span></span><span><span style="line-height: 21px;">类的什么地方。</span></span></p>
<br><p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">尽管这个文件夹里的文件可以任意命名,不过下面使一些比较典型的文件(文件命名的惯例是将元素类型包含在该名称之中):</span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px; font-family: Wingdings;"><span style="line-height: 21px;"><br></span></span><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">array.xml</span></span></strong><span><span style="line-height: 21px;"> 定义数组</span></span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px; font-family: Wingdings;"><span style="line-height: 21px;"><br></span></span><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">colors.xml </span></span></strong><span><span style="line-height: 21px;">定义</span></span><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/available-resources.html#colordrawableresources" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">color drawable</span></span></a><span><span style="line-height: 21px;">和</span></span><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/devel/resources-i18n.html#colorvals" target="_blank"><span><span style="line-height: 21px;">颜色的字符串值(color string values)</span></span></a><span><span style="line-height: 21px;">。使用</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resource.getDrawable()</span></span><span><span style="line-height: 21px;">和</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resources.getColor()</span></span><span><span style="line-height: 21px;">分别获得这些资源。</span></span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px; font-family: Wingdings;"><span style="line-height: 21px;"><br></span></span><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">dimens.xml</span></span></strong><span><span style="line-height: 21px;">定义</span></span><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/available-resources.html#dimension" target="_blank"><span><span style="line-height: 21px;">尺寸值(dimension value)</span></span></a><span><span style="line-height: 21px;">。使用</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resources.getDimension()</span></span><span><span style="line-height: 21px;">获得这些资源。</span></span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px; font-family: Wingdings;"><span style="line-height: 21px;"><br></span></span><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">strings.xml</span></span></strong><span><span style="line-height: 21px;">定义</span></span><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/available-resources.html#stringresources" target="_blank"><span><span style="line-height: 21px;">字符串(string)</span></span></a><span><span style="line-height: 21px;">值。使用</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resources.getString()</span></span><span><span style="line-height: 21px;">或者</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resources.getText()</span></span><span><span style="line-height: 21px;">获取这些资源。</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">getText()</span></span><span><span style="line-height: 21px;">会保留在</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">UI</span></span><span><span style="line-height: 21px;">字符串上应用的丰富的文本样式。</span></span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px; font-family: Wingdings;"><span style="line-height: 21px;"><br></span></span><strong><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">styles.xml</span></span></strong><span><span style="line-height: 21px;"> 定义</span></span><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/available-resources.html#stylesandthemes" target="_blank"><span><span style="line-height: 21px;">样式</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">(style)</span></span></a><span><span style="line-height: 21px;">对象。</span></span></p>
</td>
</tr>
<tr>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">res/xml/</span></p>
</td>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span><span style="line-height: 21px;">任意的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">XML</span></span><span><span style="line-height: 21px;">文件,在运行时可以通过调用</span></span><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/android/content/Resources.html#getXml(int)" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resources.getXML()</span></span></a><span><span style="line-height: 21px;">读取。</span></span></p>
</td>
</tr>
<tr>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">res/raw/</span></p>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span style="line-height: 21px;">assets/</span></p>
</td>
<td>
<p style="margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; padding: 0px;"><span><span style="line-height: 21px;">直接复制到设备中的任意文件。它们无需编译,添加到你的应用程序编译产生的压缩文件中。</span></span><span><span style="line-height: 21px;">要使用这些资源,可以调用</span></span><a style="text-decoration: none; color: #336699;" href="http://code.google.com/android/reference/android/content/Resources.html#openRawResource(int)" target="_blank"><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">Resources.openRawResource()</span></span></a><span><span style="line-height: 21px;">,参数是资源的</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">ID</span></span><span><span style="line-height: 21px;">,即</span></span><span style="line-height: 21px; font-family: Arial;"><span style="line-height: 21px;">R.raw.<em style="font-style: italic;">somefilename</em></span></span><span><span style="line-height: 21px;">。assets下也可以放置任意文件,使用Activity.this.getAssets().open("519.txt");打开</span></span></p>
</td>
</tr>
</tbody></table></span></span></td>
</tr></tbody></table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<p> </p>
"res/assets/"这里错了哟...assets没有在res文件下面的...
"res/assets/"这里错了哟...assets没有在res文件下面的...
有不全的或是不对的请指正、补充...
相关推荐
Android工程中的资源文件主要存储在`res`目录下,包括各种类型的资源,如布局、图片、字符串、颜色等。此外,`assets`目录则用于存放未经编译处理的原始文件。 1. **资源文件夹介绍** - **res/anim**:存放XML...
本示例将深入探讨如何在Android工程中播放音频文件,以帮助开发者更好地理解和实现这一功能。 首先,Android提供了多种音频播放接口,包括`MediaPlayer`、`AudioTrack`和`SoundPool`等。在这里,我们将主要讨论`...
总的来说,资源文件混淆是提高Android应用安全性的重要步骤,它能有效防止资源被轻易解析,增加逆向工程的难度。`resguard-tools`作为一款专门的混淆工具,为开发者提供了一种便捷的资源混淆方案,有助于保护应用的...
iml文件定义了模块的类型(例如Android Library或Android Application),模块的依赖关系,以及源代码和资源文件的路径等。当你导入或导出项目时,这个文件对于保持项目结构和配置的一致性至关重要。 2. android....
作为Android程序开发,我们自己在实际项目的开发过程中,经常会遇到我们打的Jar包需要动态的读取主项目工程中的资源文件,那么有没有一种好的方式,能够让Jar包非常方便的读取与展示主工程中的资源文件呢?...
使用android studio生成jar包,并且使用映射来完美调用资源文件。包含两个工程,一个如何生成jar包,一个是如何使用jar包,调用资源文件。使用详情可以关注我的blog,http://blog.csdn.net/jujishou521
开发android框架的时候需要对资源文件的处理 还有框架打jar包的时候的注意事项
### AndroidStudio工程清理工具(批处理)知识点解析 #### 一、工具概述 **AndroidStudioCleanKit**是一款专为Android Studio开发环境设计的项目清理工具,主要功能是帮助开发者高效地清理项目中的冗余文件,如...
在Android开发中,这个文件会标识出项目是一个Android工程,以便IDE提供相应的开发支持。 `default.properties`文件是早期版本的Android项目配置文件,用于指定Android项目的目标API级别和其他属性。现在的Android ...
本项目名为“Android工程文件”,显然它是一个使用Android Studio创建的项目,旨在教授如何利用百度定位SDK(Location-Based Services,简称LBS)来实现在Android应用中的定位功能。 首先,我们需要理解Android ...
- 在Android工程的`res/raw`目录下创建文本文件,例如`data.txt`。`raw`目录下的资源文件在运行时可以直接通过资源ID访问,无需SD卡权限。 2. **获取资源ID**: - 使用`R.raw.data.txt`获取到`data.txt`的资源ID...
2. 尺寸资源:在values文件夹下创建不同密度和尺寸的资源文件夹,如values-mdpi、values-hdpi等,放置对应的dimens.xml文件,定义不同屏幕尺寸下的尺寸值。 3. 图像资源:提供不同密度的图像资源,放在对应的...
- 在Eclipse中,一个Android工程通常包含以下几个关键文件夹和文件: - `src`:存放Java源代码,每个Activity(应用程序界面)通常对应一个Java类。 - `res`:资源文件夹,包括布局(layout)、图标(drawable)...
在Android开发领域,有时我们需要对APK文件进行逆向工程,以便查看或修改其内部资源。APKTool是一个强大的开源工具,专为Android应用的反编译和再打包而设计。它允许开发者提取APK中的资源文件,如图片、布局XML、...
总之,"Android歌词秀"源代码涵盖了Android开发的多个方面,包括文件解析、时间同步、UI设计、多线程处理、资源管理、用户交互以及测试策略。通过深入研究这些代码,开发者不仅可以学习到如何创建歌词应用,还能提升...
首先,`assets`目录是Android工程中的一个特殊目录,它不在编译后的APK的主资源目录下,而是用于存放应用的非代码静态资源,如文本文件、图片、数据库等。在构建过程中,这些资源会被原封不动地打包到APK中,因此在...
自制工具,将AndroidStudio 的 VectorDrawable xml 资源逆向转回 svg文件方便编辑。工具为带js的html,上方输入框贴入xml,下方输入框输出svg代码结果以及svg预览 注意目前仍未支持渐变填充
这个"Android打开本地HTML网页AndroidStudio工程.rar"文件很可能包含了一个简单的示例项目,演示如何在Android应用中加载并显示本地HTML文件。这里我们将深入探讨实现这一功能所涉及的关键知识点。 1. **WebView...
总结,Android VLC工程源码是学习和开发Android多媒体应用的宝贵资源。通过深入研究源码,开发者不仅可以掌握VLC的工作原理,还能了解到Android平台上的多媒体处理、硬件加速、网络流播放等核心技术,为构建自己的...