-
1、與一般的JAVA項(xiàng)目一樣,src文件夾是項(xiàng)目的所有包及源文件(.java)。
-
2、gen文件夾中包含了一個(gè)R.java,這個(gè)文件夾及類是在建立項(xiàng)目時(shí)自動(dòng)生成的,這個(gè)文件是只讀模式,R.java文件是定義該項(xiàng)目所有的資源文件的索引文件。
/* 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文件夾中的文件夾名相同,這也說(shuō)明了R.java是項(xiàng)目中資源索引。利用這個(gè)文件我們可以很快地找到要使用的資源。由于這個(gè)文件不能手動(dòng)編輯,所以當(dāng)在項(xiàng)目中加入了新的資源時(shí),只需要刷新一下該項(xiàng)目,R.java文件便自動(dòng)生成了所有資源的索引。
-
3、Android 4.2是項(xiàng)目中要用到的包,這個(gè)文件夾在項(xiàng)目建立時(shí)自動(dòng)生成。
-
4、Android 系統(tǒng)為每個(gè)新設(shè)計(jì)的程序提供了/assets目錄,這個(gè)目錄保存的文件可以打包在程序里。/res 和/assets的不同點(diǎn)是,android不為/assets下的文件生成ID。如果使用/assets下的文件,需要指定文件的路徑和文件名。
-
5、接下來(lái)的res文件夾中包含了項(xiàng)目的所有資源,比如高低中分辨率程序圖標(biāo)文件(drawable-hdpi、drawable-ldpi、drawable-mdpi)、布局文件(layout)、常量(values)等。
1) 我們先來(lái)看看布局文件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>
:線性版面配置,在這個(gè)標(biāo)簽中,所有的元素都是按由上到下的順序排列的。
<
RelativeLayout
>
:
相對(duì)布局配置。
android:orientation:表示這個(gè)介質(zhì)的版面配置方式,其中“vertical”代表從上到下垂直布局,而“horizontal”代表從左到右水平布局。
android:layout_width:定義當(dāng)前視圖在屏幕上所占的寬度,fill_paent即填充整個(gè)屏幕。
android:layout_height:定義當(dāng)前視圖在屏幕上所占的高度,fill_parent即填充整個(gè)屏幕。
:文本標(biāo)簽,用來(lái)顯示文字,高度設(shè)置“wrap_content”表示本文本標(biāo)簽可根據(jù)文本來(lái)改變高度。
android:text:設(shè)置TextView要顯示的內(nèi)容,“@string/hello”表示引用String.xml文件中的hello所代表的字符串
2) 下面來(lái)看常量的定義(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、接下來(lái)的AndroidManifest.xml文件,它是每個(gè)Android項(xiàng)目所必須的,是整個(gè)應(yīng)用的全局描述文件。文件說(shuō)明了應(yīng)用的名稱、所使用的圖標(biāo)、以及包含了該項(xiàng)目中所有使用的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>
.:根節(jié)點(diǎn),描述了package中所有的內(nèi)容
xmlns:android:包含命名空間的說(shuō)明,該命名空間使得Android中各種標(biāo)準(zhǔn)屬性能在文件中使用。
Package:聲明應(yīng)用程序包。
android:versionCode:該應(yīng)用程序版本代號(hào)
android:versionName:該應(yīng)用程序版本名稱
uses-sdk:該應(yīng)用程序所使用的SDK版本
:包含package中application級(jí)別組件聲明的根節(jié)點(diǎn)。此元素也可包含application的一些全局和默認(rèn)的屬性,如標(biāo)簽、icon、主題、必要的權(quán)限等。一個(gè)manifest中至多包含一個(gè)此元素
android:icon:應(yīng)用程序圖標(biāo)
android:label:應(yīng)用程序名
Activity:Activity是用戶打開的一個(gè)應(yīng)用程序的初始頁(yè)面,大部分被使用到的其他頁(yè)面也由不同的Activity所實(shí)現(xiàn)。每個(gè)Activity必須有一個(gè)標(biāo)記對(duì)應(yīng),無(wú)論它給外部使用或是只用于自己的package中。為了支持運(yùn)行時(shí)查找Activity,可包含一個(gè)或多個(gè)元素來(lái)描述Activity所支持的操作。
android:name:應(yīng)用程序默認(rèn)啟動(dòng)的Activity。
intent-filter:聲明了指定的一組組件支持的Intent值,從而形式了IntentFilter。除了能在此元素下指定不同類型的值,屬性也能放在這里來(lái)描述一個(gè)操作所需的唯一標(biāo)簽、icon和其他信息。
action:組件支持的Intent action
category:組件支持的Intent Category。這里指定了應(yīng)用程序默認(rèn)啟動(dòng)的Activity。
- 7、project.properties文件:
記錄項(xiàng)目中所需要的環(huán)境信息,比如Android的版本等,代碼中的注釋已經(jīng)把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文件
這個(gè)文件是混淆代碼的腳本配置文件.
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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