三大源码:界面布局文件+Java源文件+资源文件。
两大类型:assets目录下的原生资源,res目录下可通过资源清单访问的资源
/res/values/(此目录下的xml文件都是以resources为根元素)
字符串 string.xml R.string
<resources>
<string name="app_name">SuperDemos</string>
</resources>
颜色 colors.xml R.color
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color android:id="@+id/color1" android:layout_height="wrap_content" android:layout_width="wrap_content" name="yello">#dddddd</color>
</resources>
尺寸资源 dimens.xml R.dimen
<resources>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
数组资源 arrays.xml R.array
<array/>
<string-array/>
<integer-array/>
<plurals/>解释
<resources>
<string-array name="items">
<item>中国</item>
<item>美国</item>
<item>法国</item>
<item>英国</item>
<item>俄罗斯</item>
</string-array>
<integer-array>
<item />
</integer-array>
<plurals>
<item />
</plurals>
</resources>
Resources.getStringArray(int id);
String[]
.getIntArray(int id); int[]
obtainTypedArray(int id); TypedArray
Resources rs = getResources();
TypedArray代表一个通用类型的数组,提供getXxx(int index)方法来获取指定索引处的数组元素。
样式资源:包含多个style子元素
<resources>
<style name="样式名称" parent="继承的父样式">
<item name="android:textSize">20sp</item>
</style>
</resources>
<resources>
<style name="样式名称" parent="继承的父样式">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
Context.setTheme(int id);
也可以在application或activity的属性中设置
Attribute :属性资源,自定义View
<resources>
<attr name="duration">
</attr>
<declare-styleable name="NView">
<attr name="duration"/>
</declare-styleable>
</resources>
属性资源文件只管定义属性,至于由那个view使用用来干什么就不归他管了。具体使用见自定义View。
/res/drawable
Drawable资源:可以是各种图片,也可以是xml文件
图片资源: *.png *.jpg *.gif *.9.png等类型图片直接放到目录下,编译时会自动加载生成资源索引,因此图片名要符合Java标识符命名规则
StateListDrawable资源:组织多个drawable对象,当使用StateListDrawable作为目标组件的背景图片时,StateListDrawable
对象所显示的Drawable对象会随目标组件状态的改变而自动切换。
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable[color]=""></item>
</selector>
LayerDrawable资源:包含一个Drawable数组,按顺序绘制,最后出现的绘制在最上面(SeekBar)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable=""
android:id=""
android:top=""
android:left=""
android:bottom=""
android:right=""></item>
</layer-list>
ShapeDrawable资源:定义一个基本的几何图形
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle|oval|line|ring"指定哪种几何图形>
<corners 四角弧度/>
<gradient 渐变色填充/>
<padding 内边距/>
<size 大小 />
<solid 但种颜色填充/>
<stroke 绘制边框/>
</shape>
ClipDrawable资源:代表从其他图上截取的一个图片片段
<clip xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="指定截取的源Drawable对象"
android:clipOrientation="指定截取方向"
android:gravity="指定截取时的对齐方式"
>
</clip>
可将Drawable强制转换为ClipDrawable,调用setLevel(int level)来实现图片展开裁切的效果。
/res/anmi 动画
AnimationDrawable资源:代表一个动画,支持逐帧动画和补间动画
补间动画:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="动画变化速度"
android:shareInterpolator="设置该元素下所有变换效果是否都使用相同速度"
android:duration="持续时间">
<alpha 透明度
android:fromAlpha=""
android:toAlpha=""/>
<scale 缩放
开始状态
android:fromXScale=""
android:fromYScale=""
结束状态
android:toXScale=""
android:toYScale=""
变换中心点
android:pivotX=""
android:pivotY=""/>
<translate 位移
android:fromXDelta=""
android:fromYDelta=""
android:toXDelta=""
android:toYDelta=""
/>
<rotate 旋转
android:fromDegrees=""
android:toDegrees=""
android:pivotX=""
android:pivotY=""
/>
</set>
Property Animation资源 :属性动画
set作为根元素代表AnimatorSet对象
objectAnimator做为根元素定义ObjectAnimator动画
animator做为根元素定义ValueAnimator动画