當你要給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代碼
<?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代碼
<?xml version="1.0" encoding="utf-8"?><merge> <include layout="@layout/main_ltr"/></merge>
Strings and other simple values
用資源id做為引用
Xml代碼
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello</string> <string name="hi">@string/hello</string></resources>
Xml代碼
<?xml version="1.0" encoding="utf-8"?><resources> <color name="yellow">#f00</color> <color name="highlight">@color/red</color></resources>
本文出自“wen66”