1.src:存放全部的*.java源程序。java
2.gen:爲ADT插件自動生成的代碼文件保存路徑,裏面的R.java將保存全部的資源ID。android
3.assets:能夠存放項目一些較大的資源文件,例如:圖片、音樂、字體等。數組
4.res:能夠存放項目中全部的資源文件,例如:圖片(*.png、*.jpg)、文本等。app
5.res/drawable-hdpi:保存高分辨率圖片資源,可使用Resources.getDrawable(id)能夠得到資源類型。框架
6.res/drawable-ldpi:保存低分辯率圖片資源,可使用Resources.getDrawable(id)能夠得到資源類型。ide
7.res/drawable-mdpi:保存中等分辨率圖片資源,可使用Resources.getDrawable(id)能夠得到資源類型。佈局
8.res/layout:存放全部的佈局文件,主要是用於排列不一樣的顯示組件,在Android程序中要讀取此配置。字體
9.res/values: 存放一些資源文件的信息,用於讀取文本資源,在本文件夾之中有一些約定的文件名稱:動畫
.attrs.xml:自定義屬性值的:具體能夠參考 http://blog.csdn.net/jiangwei0910410003/article/details/17006087 · arrays.xml:定義數組數據;this
定義以下:
<?xml version="1.0" encoding="utf-8" ?> <resources> <string-array name="MyArray"> <item name="1,35,3">第一</item> <item name="5,34,0">第二</item> <item name="1,30,1">第三</item> <item name="2,31,0">第四</item> </string-array> </resources> 在代碼中讀取: Resources r = this.getResources(); String[] ary = r.getStringArray(R.array.MyArray); · colors.xml:定義表示顏色的數據; · dimens.xml:定義尺度,可使用Resources.getDimension()得到這些資源; · strings.xml:定義字符串,可使用Resources.getString()或Resources.getText()方法得到這些資源; · styles.xml:定義顯示的樣式文件; <resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="android:windowNoTitle">true</item> </style> <!-- 全局的Activity切換動畫 --> <style name="MyTheme" parent="AppTheme"> <item name="android:windowAnimationStyle">@style/ActivityAnimation</item> </style> <style name="ActivityAnimation"> <!-- 打開activity,設置activity進入展現動畫 --> <item name="android:activityOpenEnterAnimation">@anim/pubblico_activity_anim_push_right_in</item> <!-- 打開activity,設置上個activity離開動畫 --> <item name="android:activityOpenExitAnimation">@anim/pubblico_activity_anim_push_left_out</item> <!-- 結束activity,設置上個activity進入動畫 --> <item name="android:activityCloseEnterAnimation">@anim/pubblico_activity_anim_push_left_out</item> <!-- 結束activity,設置當前activity離開動畫 --> <item name="android:activityCloseExitAnimation">@anim/pubblico_activity_anim_push_right_out</item> </style> </resources>
10.res/raw:自定義的一些原生文件所在目錄,像音樂、視頻等文件格式。存放直接複製到設備中的任意文件。它們無需編譯,添加到你的應用程序編譯產生的壓縮文件中。要使用這些資源,能夠調用Resources.openRawResource(),參數是資源的ID也能夠用,即R.raw.somefilename,Resources.getRawResource()方法能夠得到這些資源。
11.res/xml:用戶自定義的XML文件,全部的文件在程序運行時編譯到應用程序之中,在程序運行時可使用Resources.getXML()方法獲取。
12.res/anim:用於定義動畫對象。存放定義了補間動畫(tweened animation)或逐幀動畫(frameby frame animation)的XML文件。(該目錄下也能夠存放定義property animations的XML文件,可是最好仍是分開存放)
13.res/animator:存放定義了propertyanimations(android 3.0新定義的動畫框架)的XML文件
14.res/color/:存放定義了顏色狀態列表資源(ColorState List Resource)的XML文件
15.res/drawable/:存放定義了圖片狀態列表資源(ColorState List Resource)的XML文件
16.res/menu/:存放定義了應用程序菜單資源的XML文件。正確建立文件的方法:new Folder,名字menu,new Other——Android——XML,選擇menu類型,填寫名稱,肯定便可。菜單資源文件必須放在res/menu目錄中。菜單資源文件必須使用<menu>標籤做爲根節點。除了<menu>標籤外,還有另外兩個標籤用於設置菜單項和分組,這兩個標籤是<item>和<group>。
注意:
對於res/color和res/drawable這兩個文件中的內容在這做一下詳解:
首先說一下color文件夾,在這個文件夾下放的是color_selector.xml等文件,主要是用於背景色的selector,好比TextView中的textColor屬性,點擊改變TextView中的字體顏色,在這個文件中的文件color_selector.xml中定義以下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="false" android:color="@color/not_pressed" /> <item android:state_selected="false" android:state_focused="false" android:state_pressed="false" android:color="@color/not_pressed"/> <item android:state_selected="true" android:color="@color/pressed" /> <item android:state_focused="true" android:color="@color/pressed" /> <item android:state_pressed="true" android:color="@color/pressed" /> </selector>
主要的屬性是android:color引用不一樣的色值,而這些色值是在values/color.xml文件中定義的,好比:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="not_pressed">#000000</color>
<color name="pressed">#ffffff</color>
</resources>
同時也能夠發現,在color_selector.xml中沒有android:drawable屬性,我不知道Android中是根據什麼判斷何時有android:drawable屬性,何時有android:color屬性的
下面來看一下res/drawable文件夾中的文件,這個文件夾中的文件drawable_selector.xml,主要是用於背景圖的使用,Button中的android:background,點擊改變背景,drawable_selecor.xml文件的定義:
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="false" android:drawable="@drawable/info_collect_btn_normal_bg"/> <item android:state_selected="false" android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/info_collect_btn_normal_bg" /> <!-- Non focused states --> <item android:state_selected="true" android:drawable="@drawable/info_collect_btn_pressed_bg" /> <!-- Focused states --> <item android:state_focused="true" android:drawable="@drawable/info_collect_btn_pressed_bg" /> <!-- Pressed --> <item android:state_pressed="true" android:drawable="@drawable/info_collect_btn_pressed_bg" /> </selector>
這裏的info_collect_btn_normal_bg和info_collect_btn_pressed_bg是圖片資源,放在drawableXX文件夾下的。
同時也發現了在drawable_selector.xml中沒有android:color屬性,結合上面的color_selector.xml中沒有android:drawable屬性,知道了Android應該是根據文件夾來判斷的,在color文件夾下的文件有android:color屬性,在drawable文件夾下的文件有android:drawable屬性
同時還要注意的是:像textColor和background屬性引用到的文件不能亂引用,好比textColor引用了drawable_selector.xml,background引用了color_selector.xml會報錯的。因此要注意使用。
可是如今有個問題:假設Button如今想點擊變成綠色,不點擊變成紅色,這時候怎麼辦?
首先確定要用background的屬性-->那確定就要用drawable_selector.xml文件引用,因此在drawable_selector_.xml中將android:drawable="@drawable/info_collect_btn_normal_bg"改爲android:drawable="@color/not_pressed"便可,這裏可能有個誤解就是android:drawable只能引用drawable資源,可是事實證實這個誤解是多餘的!原理能夠參考attr詳解中。本文轉載自:http://blog.csdn.net/jiangwei0910410003/article/details/16985955