-
1、與一般的JAVA項目一樣,src文件夾是項目的所有包及源文件(.java)。
-
2、gen文件夾中包含了一個R.java,這個文件夾及類是在建立項目時自動生成的,這個文件是只讀模式,R.java文件是定義該項目所有的資源文件的索引文件。
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package
com
.
example
.
practice
;
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
id
{
public
static
final
int
menu_settings
=
0x7f070002
;
public
static
final
int
ok
=
0x7f070001
;
public
static
final
int
show
=
0x7f070000
;
}
public
static
final
class
layout
{
public
static
final
int
activity_main
=
0x7f030000
;
}
public
static
final
class
menu
{
public
static
final
int
activity_main
=
0x7f060000
;
}
public
static
final
class
string
{
public
static
final
int
app_name
=
0x7f040000
;
public
static
final
int
hello
=
0x7f040003
;
public
static
final
int
hello_world
=
0x7f040001
;
public
static
final
int
menu_settings
=
0x7f040002
;
}
public
static
final
class
style
{
public
static
final
int
AppBaseTheme
=
0x7f050000
;
public
static
final
int
AppTheme
=
0x7f050001
;
}
}
可以看到文件中定義了很多常量,這些常量的名字都與res文件夾中的文件夾名相同,這也說明了R.java是項目中資源索引。利用這個文件我們可以很快地找到要使用的資源。由于這個文件不能手動編輯,所以當在項目中加入了新的資源時,只需要刷新一下該項目,R.java文件便自動生成了所有資源的索引。
-
3、Android 4.2是項目中要用到的包,這個文件夾在項目建立時自動生成。
-
4、Android 系統為每個新設計的程序提供了/assets目錄,這個目錄保存的文件可以打包在程序里。/res 和/assets的不同點是,android不為/assets下的文件生成ID。如果使用/assets下的文件,需要指定文件的路徑和文件名。
-
5、接下來的res文件夾中包含了項目的所有資源,比如高低中分辨率程序圖標文件(drawable-hdpi、drawable-ldpi、drawable-mdpi)、布局文件(layout)、常量(values)等。
1) 我們先來看看布局文件activity_main.xml:
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".MainActivity"
>
<TextView
android:id=
"@+id/show"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_centerHorizontal=
"true"
android:layout_centerVertical=
"true"
android:text=
"@string/hello_world"
/>
<Button
android:id=
"@+id/ok"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentLeft=
"true"
android:layout_alignParentTop=
"true"
android:layout_marginLeft=
"22dp"
android:layout_marginTop=
"18dp"
android:text=
"@string/hello"
/>
</RelativeLayout>
:線性版面配置,在這個標簽中,所有的元素都是按由上到下的順序排列的。
<
RelativeLayout
>
:
相對布局配置。
android:orientation:表示這個介質的版面配置方式,其中“vertical”代表從上到下垂直布局,而“horizontal”代表從左到右水平布局。
android:layout_width:定義當前視圖在屏幕上所占的寬度,fill_paent即填充整個屏幕。
android:layout_height:定義當前視圖在屏幕上所占的高度,fill_parent即填充整個屏幕。
:文本標簽,用來顯示文字,高度設置“wrap_content”表示本文本標簽可根據文本來改變高度。
android:text:設置TextView要顯示的內容,“@string/hello”表示引用String.xml文件中的hello所代表的字符串
2) 下面來看常量的定義(strings.xml文件):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string
name=
"app_name"
>
practice
</string>
<string
name=
"hello_world"
>
Hello world!
</string>
<string
name=
"menu_settings"
>
Settings
</string>
<string
name=
"hello"
>
hello
</string>
</resources>
- 6、接下來的AndroidManifest.xml文件,它是每個Android項目所必須的,是整個應用的全局描述文件。文件說明了應用的名稱、所使用的圖標、以及包含了該項目中所有使用的Activity、Service、Receiver等組件,該文件中代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.example.practice"
android:versionCode=
"1"
android:versionName=
"1.0"
>
<uses-sdk
android:minSdkVersion=
"8"
android:targetSdkVersion=
"16"
/>
<application
android:allowBackup=
"true"
android:icon=
"@drawable/ic_launcher"
android:label=
"@string/app_name"
android:theme=
"@style/AppTheme"
>
<activity
android:name=
"com.example.practice.MainActivity"
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>
.:根節點,描述了package中所有的內容
xmlns:android:包含命名空間的說明,該命名空間使得Android中各種標準屬性能在文件中使用。
Package:聲明應用程序包。
android:versionCode:該應用程序版本代號
android:versionName:該應用程序版本名稱
uses-sdk:該應用程序所使用的SDK版本
:包含package中application級別組件聲明的根節點。此元素也可包含application的一些全局和默認的屬性,如標簽、icon、主題、必要的權限等。一個manifest中至多包含一個此元素
android:icon:應用程序圖標
android:label:應用程序名
Activity:Activity是用戶打開的一個應用程序的初始頁面,大部分被使用到的其他頁面也由不同的Activity所實現。每個Activity必須有一個標記對應,無論它給外部使用或是只用于自己的package中。為了支持運行時查找Activity,可包含一個或多個元素來描述Activity所支持的操作。
android:name:應用程序默認啟動的Activity。
intent-filter:聲明了指定的一組組件支持的Intent值,從而形式了IntentFilter。除了能在此元素下指定不同類型的值,屬性也能放在這里來描述一個操作所需的唯一標簽、icon和其他信息。
action:組件支持的Intent action
category:組件支持的Intent Category。這里指定了應用程序默認啟動的Activity。
- 7、project.properties文件:
記錄項目中所需要的環境信息,比如Android的版本等,代碼中的注釋已經把project.properties解釋得很清楚了:
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target
=
android
-
17
- 8、proguard-project.txt文件
這個文件是混淆代碼的腳本配置文件.
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
