idea裏面的文件目錄結構圖分析:
1、asserts文件用於存放項目中用到的多媒體文件,但是與res的區別是res文件下的文件會在項目運行時被載入內存中,而asserts文件下的文件是在被用到的時候纔會被載入內存中(這個很像hibernate中那個load跟get方法的區別有木有)。所以可以用於存放諸如視頻文件、聲音文件的大文件。
2、gen文件夾,該文件時自動生成的,其下存在一個R.java文件,這個文件可以理解爲一個全局的資源文件的索引,我們來看一下這個文件的內容:
package com.example;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040000;
public static final int hello=0x7f040001;
}
}
字段都被賦予了一個十六進制數,而這個文件中的所定義的常量的名字與res文件下的資源文件的名字是一致的,這個是不是很容易就會聯想到數據庫中的主鍵ID呢。當在Activity中需要調用資源文件中定義的值的時候就需要這個ID來獲取了,例如:getResources().getColor(resourceId)可以調用color.xml中定義的資源
還有一個BuildConfig文件,這個文件可以理解成自定義常量集,有利於程序員們對程序的維護
3、libs文件夾,這個很明瞭,跟java項目中一樣,是一個用於存放第三方jar包的文件
4、res文件夾,存放應用程序中的各類多媒體文件,按資源文件類型主要分爲三個子目錄drawable-*dpi、layout、values。
drawable文件夾用於存放圖片文件,如png、jpg,上圖中將drawable分成了四個子文件,主要是存放不同分辨率的圖標,其中xdpi是超高分辨率,hdpi是高分辨率,mdpi是中等分辨率,ldpi是低分辨率;
layout文件夾用於存放頁面佈局的xml文件,如:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
這表明是一個線性佈局,佈局裏放了一個文本組件。文本組件中的@符號表示的是引用;
values文件夾是定義格式參數的xml文件,其中包括字符串描述文件strings.xml、顏色描述文件color.xml、數組描述文件array.xml、樣式描述文件style.xml等。
5、src文件夾就是用於存放各種java源文件的
6、AndroidManifest.xml是 應用程序描述文件,類似於java項目中的web.xml,如下:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="18"/> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> <activity android:name="MyActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>
7、ant.properties文件用於在使用ant構建項目的時候覆蓋某些被定義默認的值,例如
'source.dir'本地的java源文件夾目錄
'out.dir' 本地編譯項目輸出的文件夾目錄
8、loacal.properties文件是Android Tools自動生成的,主要包含一些本地特殊配置信息,如
sdk.dir=D:\\Program Files (x86)\\android\\sdk\\sdk
9、build.xml文件項目中的屬性文件的配置文件
10、project.properties文件也是 Android Tools自動生成的
綜合整理分析如圖: