Android---(1),综述,项目文件说明。

时间:2012/11/12

书籍:Beginning.Android.4.Application.Development

开发环境:eclipse


1.安卓的架构

1.1内核(Linux kernel)

--安卓采用的是Linux内核,在内核层面包含了对于各种安卓应将的驱动。

1.2库文件(Libraries)

--提供了Android OS的各种库文件。

1.3安卓运行时(Android runtime)

--跟Libraries在同一级层面上,为用户提供了运行java程序的平台。也包括了Dalvik virtual machine,一个为安卓特制的虚拟机。

1.4应用程序框架(Application Framework)

--为用户开发提供了各种可能性。(-_-|||)

1.5应用程序(Applications)

--安卓系统上运行的各种程序


2.项目文件剖析



2.1src

--包含了当前项目的.java源文件,在java你可以编辑项目的代码,java文件以你当前项目的package name 来命名。(不过在最新的开发环境下貌似是用MainActivity.java来命名)

2.2gen

--包含了R.java文件,一个由编译器自动生成的文件,用于提供引用项目里面的资源(“gen — Contains the R.java fi le, a compiler-generated file that references all the resources found in your project.”)
2.3Android 4.0 library

--这个文件夹包含一个文件--Android 4.0 library ,用来提供应用程序所需的所有类库文件。

2.4assets

--“This folder contains all the assets used by your application, such as HTML, text fi les, databases, etc.” (不懂求教)。

2.5bin

--包含了由ADT生成的文件,一般来说是生成Android Package文件(apk)。包含了运行一个安卓应用程序的所有。
2.6res

--包含了应用程序的所有资源(就是应用程序图标什么的)。


2.7AndroidManifest.xml

--这个是安卓应用的Manifest文件,可用于指定安卓应用的许可和其他特性。(“This is the manifest fi le for your Android application. Here you specify the permissions needed by your application, as well as other features (such as intent-fi lters,
receivers, etc.).”)

3.@string用法


“@string”用来指定在strings.xml文件内的字符串,例如:“@string/hello”是指定在strings.xml内的hello字符串,其内容为“hello world !”,如下:

Hello World, HelloWorldActivity!
HelloWorld

强烈建议将所有的字符串常量放在此文件中然后用@string语法来使用字符串,以便于在不同语言(非编程语言)使用应用程序。例如:
定义一个名叫test的字符串(在strings.xml中)
this is a test string!
则可以在其他地方用“@string/test”来表示里面的内容:this is a test string !。

4.manifest 文件

另外一个重要的文件是Manifest文件。注意如下的Manifest文件:












注意一下几点:
(1)文件定义了Package的名字叫net.learn2develop.HelloWorld(
package=”net.learn2develop.HelloWorld”

(2)代码的版本(version code)是1(通过android:versionCode指定),可以用这个属性来决定哪个程序需要更新(This value is used to identify the version number of your application. It can be used to programmatically determine whether an application needs to be upgraded.)

(3)软件的版本号为1.0(通过android:versionName来指定),这个主要用于展示给用户。

(4)android:minSdkVersion属性指定了运行此程序的最低android OS要求。

(5)此项目有一个活动(activity),代表这个活动的标签和这个活动一样的名字(android:name=“.HelloWorldActivity”),在activity的标签内,有个叫intent-filter的元素:

1.,指定了此程序的主入口(entry point)。

2.category 的值是 android.intent.category.LAUNCHER 表示程序可以从设备的launcher icon进入。

5.R.java

当你增加越来越多的文件夹和文件进入你的程序里面,R.java会自动的改变其中的内容。请不要擅自修改。编译器会自动生成其中的内容。

6.UI

最终,和UI界面连接的代码是setContentView() 方法,在HelloWorldActivity.java(或者是MainActivity.java文件)文件中,如下:
R.layout.main引用了res/layout文件夹中的main.xml(或者activity_main)文件,
package net.learn2develop.HelloWorld;
import android.app.Activity;
import android.os.Bundle;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}				

你可能感兴趣的:(安卓学习。)