Android应用资源

三大源码:界面布局文件+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>


主题资源:只对所有或指定activity起作用,用来改变窗口外观的格式
<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动画

/res/xml  定义原始XML资源

Resources.getXml(int id); XmlResourceParser 解析器对象 android默认使用pull解析器解析xml文件
    .openRawResource(int id); InputStream  xml文档对应的输入流 获得输入流即可自行选择解析器

原始资源

/res/raw 会生成索引项



/assets 需要通过AssetManager来管理 AssetManager=getAssets();
InputStream open(String fileName)
AssetFileDescriptor openFd(String fileName)












版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/imzcq/p/4886093.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值