第十三章 Android系统的资源



1、资源的基础问题
res/assert
getResources().getString(R.string.hello);
getResources().getAssert().open("test.png");
2、本地化
240*320 ldpi
320*480 mdpi
480*800 hdpi
values-zh-rCN-port
3、字符串资源
<resources>
  <string-array name="planets_array">
    <item>Mercury</item>
    <item>Mercury</item>
  </string-array>
</resources>

Resources res = getResources();
String[] plants = res.getStringArray(R.array.planets_array);
字符串中有单引号的要用双引号括起来
<b>/<i><u>
占位符%1
String.format(String, object);
4、布局资源
xmlns:android指Android SDK中R类的位置
<requestFocus/>
5、图像资源
9.png
*图层(layer)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="">
    <item>
 <bitmap android:src="@drawable/image1" android:gravity="center" />
    </item>
    <item android:top="10dp" android:left="10dp">
 <bitmap android:src="@drawable/image2" android:gravity="center" />
    </item>
    <item android:top="20dp" android:left="20dp">
 <bitmap android:src="@drawable/image1" android:gravity="center" />
    </item>
</layer-list>
*图像状态资源(State)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">
    <item android:state_pressed="true" android:drawable="@drawable/pressed" />
    <item android:state_focused="true" android:drawable="@drawable/focused" />
    <item android:drawable="@drawable/normal" />
</selector>
*图像级别资源(Level-list)
ImageView.setImageLevel/Drawable.setLevel
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="">
    <item android:drawable="@drawable/lamp_off" android:minLevel="6" android:maxLevel="10" />
    <item android:drawable="@drawable/lamp_on" android:minLevel="12" android:maxLevel="20" />
</level-list>
淡入淡出资源(Cross-fade)
剪切资源(Clip)和外形资源(Shape)
<?xml version="1.0" encoding="utf-8"?>
<clip xmlns:android=""
    android:drawable="@drawable/progress"
    android:clipOrientation="horizontal"
    android:gravity="left" />
ImageView imageView = (ImageView)findViewById(R.id.image);
ClipDrawable drawable = (ClipDrawable)imageView.getBackground();
drawable.setLevel(3000);   
6、其它资源
1dip=1px(only 屏幕160px)


你可能感兴趣的:(第十三章 Android系统的资源)