欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android學(xué)習(xí)筆記(二)App工程文件分析

 更新時(shí)間:2014年07月30日 10:13:16   投稿:hebedich  
之前寫過一篇關(guān)于安卓環(huán)境配置以及第一個(gè)app的制作過程,下面我們來進(jìn)一步,分析下APP工程文件

App工程文件分析

關(guān)于如何創(chuàng)建一個(gè)最簡(jiǎn)單的Android App請(qǐng)參照鏈接:

《 Android學(xué)習(xí)筆記(一)環(huán)境安裝及第一個(gè)hello world 》 http://www.dbjr.com.cn/article/52593.htm

創(chuàng)建完的工程文件如下圖所示,本文對(duì)一些主要的文件進(jìn)行分析。

enter image description here
src文件分析

App源文件如圖:

enter image description here
打開源文件 MainActivity.java 可看到如下代碼:

enter image description here
源碼主要功能如下:

App源文件目錄

package com.example.firstapp; 

導(dǎo)入App所需的類

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

MainActivity繼承自Activity

public class MainActivity extends Activity

重載onCreate方法,使用布局文件初始化Activity

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
} 

重載onCreateOptionsMenu方法,使用布局文件初始化Menu

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
}

gen與res文件

gen文件夾下R.java文件在創(chuàng)建工程時(shí)自動(dòng)創(chuàng)建,為只讀文件,定義了項(xiàng)目所有資源的索引,里面的每個(gè)靜態(tài)類都與一個(gè)資源對(duì)應(yīng)。

例如:

1. 類drawable與res中包含drawable字樣的文件夾關(guān)聯(lián)

2. 類layout與res中l(wèi)ayout文件夾關(guān)聯(lián)

3. 類menu與res中menu文件夾關(guān)聯(lián)

res文件夾下是App所使用的資源文件,其中:

1. drawable與icon相關(guān)

2. layout與布局相關(guān)

3. menu與menu布局相關(guān)

4. value字樣的定義了項(xiàng)目配置中使用的值

舉例: 界面中的文字

value的文件夾下的strings.xml文件中定義了名稱為hello_world的字符串,其值為" hello world! "
layout文件夾下的activity_main.xml中定義了Textveiw中的文字為hello_world字符串。
Android Menifest.xml

App的主要配置文件,內(nèi)容如下:

配置App信息

package="com.example.firstapp"
android:versionCode="1"
android:versionName="1.0"  

配置SDK等級(jí)

android:minSdkVersion="8"
android:targetSdkVersion="19"

配置App資源

配置App的圖標(biāo)、名稱及主題等,其資源與res文件夾對(duì)應(yīng)。 

android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" 

 
配置App的Activity和App名稱

android:name="com.example.firstapp.MainActivity"
android:label="@string/app_name" 

配置App的intent-filter

action

  android:name="android.intent.action.MAIN"
category

  android:name="android.intent.category.LAUNCHER"

最后

以上為App工程文件分析,個(gè)人理解,僅供參考。

相關(guān)文章

最新評(píng)論