http://androidappdocs-staging.appspot.com/sdk/index.html)把a(bǔ)ndroid-sdk_r09-windows.zip下了回來,本來以為下了這個(gè)就能開始寫helloWorld,點(diǎn)知里面根本沒有開發(fā)的SDK和相關(guān)的開發(fā)工具,通過這地址https://dl-ssl.google.com/android/eclipse/給eclipse安裝ADT插件。安裝完ADT,利用SDK Manager.exe開始漫長的SDK下載,足足下了兩個(gè)晚上才下完。按著它官方的Tutorials,等了兩個(gè)晚上終于可以開始HelloWorld。
HelloAndroid.java
import android.app.Activity;
import android.os.Bundle;


public class HelloAndroid extends Activity
{

/** *//** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
下面是個(gè)人對這兩個(gè)文件的小小見解:
main.xml用來描述程序的用戶界面,感覺通過xml來描述頁面布局這方式很流行,Silverlight使用XAML描述頁面布局,QT使用QML描述界面,看來XML UI描述語言在桌面應(yīng)用將會(huì)更廣泛,在PB、Delphi、VC、VB年代,根據(jù)還未聽過有XML UI,不過HTML在BS的應(yīng)用倒是讓所有人如雷貫耳,哈哈。android的XML UI與QT相比,還弱了點(diǎn),因?yàn)镼ML支持js,不知哈時(shí)候,android能支持js,不過寫這篇文章的前一天剛好看到Qt for Android (Alpha) 發(fā)布新聞,就是不知java版的SDK哈時(shí)候能做到這一步。
HelloAndroid繼承Activity,Activity具有自己的生命周期,也就是按一定的事件流程運(yùn)行,從開始到銷毀的事件流程為
void onCreate(Bundle savedInstanceState)
void onStart()
void onRestart()
void onResume()
void onPause()
void onStop()
void onDestroy()
這讓我覺得它和applet非常相似,
applet生命周期
void init()
void start()
void stop()
void destroy()
目前android還不熟悉,暫寫這么多記錄下來,有空再繼續(xù)學(xué)習(xí)。

]]>