`

android资源别名

 
阅读更多
详细请参考: http://developer.android.com/guide/topics/resources/providing-resources.html 的 Creating alias resources

当你要给android的多种设备开发时, 要准备在多个configuration 下的资源,当然还要提供默认源. 如果在多个configuration下的资源是一样时, 你可以把这相同的资源拷贝到相应的目录下, 不过这不是一个好的实践, 实际上我们可以使用资源别名.

不过该方法不适用于animation,  menu, raw, 和xml目录下的资源.

如有个icon.png图片, res/drawable-en-rCA/, res/drawable-fr-rCA/ 两种configuration要适应, 它们的icon.png图片是一样的. 这时你可以把icon.png改个名字如 icon_alais.png放到res/drawable目录下, 然后在 res/drawable-en-rCA/, res/drawable-fr-rCA/ 目录下用icon.xml文件对这个icon_alais.png进行引用. 在生成的R类里, 我们用R.drawable.icon这个变量进行引用

Drawable
用<bitmap> element 进行资源的引用
<?xml version="1.0" encoding="utf-8"?><bitmap xmlns:android="http://schemas.android.com/apk/res/android"    android:src="@drawable/icon_ca" />


Layout
使用<include>和<merge>元素
<?xml version="1.0" encoding="utf-8"?><merge>    <include layout="@layout/main_ltr"/></merge>


Strings and other simple values
用资源id做为引用
<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello</string>    <string name="hi">@string/hello</string></resources>


<?xml version="1.0" encoding="utf-8"?><resources>    <color name="yellow">#f00</color>    <color name="highlight">@color/red</color></resources>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics