歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android應用程序下res文件夾的介紹

Android應用程序下res文件夾的介紹

日期:2017/3/1 10:34:29   编辑:Linux編程

res/drawable 專門存放png、jpg等圖標文件。在代碼中使用getResources().getDrawable(resourceId)獲取該目錄下的資源。

res/layout 專門存放xml界面文件,xml界面文件和HTML文件一樣,主要用於顯示用戶操作界面。

res/values 專門存放應用使用到的各種類型數據。不同類型的數據存放在不同的文件中,如下:

· strings.xml 定義字符串和數值,在Activity中使用getResources().getString(resourceId) 或getResources().getText(resourceId)取得資源。它的作用和struts中的國際化資源文件一樣。

<?xml version="1.0" encoding="UTF-8"?>

<resources>

<string name="mystring">我的字符串</string>

</resources>

· arrays.xml 定義數組。

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string-array name="colors">

<item>red</item>

<item>yellow</item>

<item>green</item>

<item>blue</item>

</string-array>

</resources>

· colors.xml 定義顏色和顏色字串數值,你可以在Activity中使用getResources().getDrawable(resourceId) 以及getResources().getColor(resourceId)取得這些資源。例子如下:

<?xml version="1.0" encoding="UTF-8"?>

<resources>

<color name="contents_text">#ff0000</color>

</resources>

· dimens.xml 定義尺寸數據,在Activity中使用getResources().getDimension(resourceId) 取得這些資源

<?xml version="1.0" encoding="UTF-8"?>

<resources>

<dimen name="key_height">50dip</dimen>

</resources>

· styles.xml 定義樣式。

<?xml version="1.0" encoding="utf-8"?>

<resources>

<style name="myText" parent="@style/Text">

<item name="Android:textSize">18sp</item>

<item name="android:textColor">#0066FF</item>

</style>

</resources>

res/anim/ 存放定義動畫的XML文件。

res/xml/ 在Activity中使用getResources().getXML()讀取該目錄下的XML資源文件。

res/raw/ 該目錄用於存放應用使用到的原始文件,如音效文件等。編譯軟件時,這些數據不會被編譯,它們被直接加入到程序安裝包裡。為了在程序中使用這些資源,你可以調用getResources().openRawResource(ID) , 參數ID形式:R.raw.somefilename。

Copyright © Linux教程網 All Rights Reserved