【移動應(yīng)用開發(fā)技術(shù)】Android 中的目錄結(jié)構(gòu)有哪些_第1頁
【移動應(yīng)用開發(fā)技術(shù)】Android 中的目錄結(jié)構(gòu)有哪些_第2頁
【移動應(yīng)用開發(fā)技術(shù)】Android 中的目錄結(jié)構(gòu)有哪些_第3頁
【移動應(yīng)用開發(fā)技術(shù)】Android 中的目錄結(jié)構(gòu)有哪些_第4頁
免費(fèi)預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

【移動應(yīng)用開發(fā)技術(shù)】Android中的目錄結(jié)構(gòu)有哪些

這篇文章將為大家詳細(xì)講解有關(guān)Android中的目錄結(jié)構(gòu)有哪些,文章內(nèi)容質(zhì)量較高,因此在下分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。1、Android項目目錄結(jié)構(gòu)android項目和java項目一樣,,src文件夾是項目的所有包及源文件(.java),res文件夾中包含了項目中的所有資源,比如:程序圖標(biāo)(drawable)、布局文件(layout)、常量(values)。android項目中多了gen文件夾,里面是R.java文件,定義該項目所有資源的索引文件。還有一個android項目必須的AndroidManfest.xml文件。項目結(jié)構(gòu)圖如下:1R.java文件是項目創(chuà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.hanfeng.demo;

public

final

class

R

{

public

static

final

class

attr

{

}

public

static

final

class

drawable

{

public

static

final

int

icon=0x7f020000;

}

public

static

final

class

layout

{

public

static

final

int

main=0x7f030000;

}

public

static

final

class

string

{

public

static

final

int

app_name=0x7f040001;

public

static

final

int

hello=0x7f040000;

}

}通過上面代碼,我們可以看到這些常量與res文件夾中的文件名字一樣,說明了R.java文件存儲了該項目中的所有資源索引。R.java文件的存在,方便資源的使用,當(dāng)我們在項目中加入新資源,只需刷新項目,R.java文件就會自動生成所有資源的索引。分析上面的xml文件:2AndroidManfest.xml文件包含了項目中所有使用的Activity、Service、Receiver,代碼如下:<?xml

version="1.0"

encoding="utf-8"?>

<manifest

xmlns:android="/apk/res/android"

package="com.hanfeng.demo"

android:versionCode="1"

android:versionName="1.0">

<uses-sdk

android:minSdkVersion="8"

/>

<application

android:icon="@drawable/icon"

android:label="@string/app_name">

<activity

android:name=".AndroidTest"

android:label="@string/app_name">

<intent-filter>

<action

android:name="ent.action.MAIN"

/>

<category

android:name="ent.category.LAUNCHER"

/>

</intent-filter>

</activity>

</application>

</manifest>

分析上面的xml文件:【xmlns:android】:包含命名空間的聲明。xmlns:android="/apk/res/android",使得Android中各種標(biāo)準(zhǔn)屬性能夠在文件中使用,提供大部分元素的數(shù)據(jù)?!緋ackage】:聲明應(yīng)用程序包。【application】:包含package中application級別組件聲明的根節(jié)點。此元素耶可包含application的一些全局和默認(rèn)的屬性,如標(biāo)簽、icon、主題、必要權(quán)限等。一個manifest能夠包含零個或一個此元素,不能大于一個。【android:icon】:應(yīng)用程序圖標(biāo)?!綼ndroid:lebel】:應(yīng)用程序名字?!続ctivity】:用戶交互工具?!綼ndroid:name】:應(yīng)用程序默認(rèn)啟動的Activity?!緄ntent-filter】:聲明了指定一組組件支持的Intent值,從而形成IntentFilter?!綼ction】:組件支持的Intentaction?!綾ategory】:組件支持的IntentCategory。指定應(yīng)用程序默認(rèn)啟動的Activity。【uses-sdk】:應(yīng)用程序所使用的sdk版本。3String.xml資源文件中的常量定義。代碼如下:<?xml

version="1.0"

encoding="utf-8"?>

<resources>

<string

name="hello">Hello

World,

AndroidTest!</string>

<string

name="app_name">AndroidDemo</string>

</resources>從上面的代碼可以看出,文件中定義的字符串資源常量"hello"、"app_name"指向了R.java文件中的字符串資源。下面看如何使用定義的這些資源。我們可以通過Context的getResource實例化一個Resource對象,然后通過Resource的getSting方法獲取指定索引的字符串。代碼如下:

Resource

r

=

this.getContext().getResource();

String

appname

=

((String)

r.getString(R.string.app_name));

String

hello

=

((String)

r.getString(R.string.hello));4main.xml布局文件,代碼如下:<?xml

version="1.0"

encoding="utf-8"?>

<LinearLayout

xmlns:android="/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>布局參數(shù)解析:【<linearLayout>】:線性版面配置,在這個標(biāo)簽中,所有元件都是按由上到下的排列排成?!綼ndroid:orientation】:表示這個介質(zhì)的版面配置方式是從上到下的垂直地排列其內(nèi)部視圖?!綼ndroid:layout_width】:定義當(dāng)前視圖在屏幕上所占的寬度,fill_parent即填充整個屏幕。【android:layout_height】:定義當(dāng)前視圖在屏幕上所占的高度。【wrap_weight】:隨著文字欄位的不同而改變這個視圖的高度或?qū)挾取?AndroidTest.java項目的豬程序文件。代碼如下:package

com.hanfeng.demo;

import

android.app.Activity;

import

android.os.Bundle;

public

class

AndroidTest

extends

Activity

{

/**

Called

when

the

activity

is

first

created.

*/

@Override

public

void

onCreate(Bundle

savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

}主程序Android

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論