posts - 59, comments - 244, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          開始android的HelloWorld

          Posted on 2011-02-23 00:44 penngo 閱讀(2938) 評論(2)  編輯  收藏 所屬分類: android
          android很火,也來學習下,上段時間上它官網(官網的訪問不了,只能訪問http://androidappdocs-staging.appspot.com/sdk/index.html)把android-sdk_r09-windows.zip下了回來,本來以為下了這個就能開始寫helloWorld,點知里面根本沒有開發的SDK和相關的開發工具,通過這地址https://dl-ssl.google.com/android/eclipse/給eclipse安裝ADT插件。安裝完ADT,利用SDK Manager.exe開始漫長的SDK下載,足足下了兩個晚上才下完。按著它官方的Tutorials,等了兩個晚上終于可以開始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>


          下面是個人對這兩個文件的小小見解:

          main.xml用來描述程序的用戶界面,感覺通過xml來描述頁面布局這方式很流行,Silverlight使用XAML描述頁面布局,QT使用QML描述界面,看來XML UI描述語言在桌面應用將會更廣泛,在PB、Delphi、VC、VB年代,根據還未聽過有XML UI,不過HTML在BS的應用倒是讓所有人如雷貫耳,哈哈。android的XML UI與QT相比,還弱了點,因為QML支持js,不知哈時候,android能支持js,不過寫這篇文章的前一天剛好看到Qt for Android (Alpha) 發布新聞,就是不知java版的SDK哈時候能做到這一步。
          HelloAndroid繼承Activity,Activity具有自己的生命周期,也就是按一定的事件流程運行,從開始到銷毀的事件流程為
          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還不熟悉,暫寫這么多記錄下來,有空再繼續學習。


          評論

          # re: 開始android的HelloWorld  回復  更多評論   

          2011-02-23 15:59 by 步步為營
          Android最近好火呀,我也在學,呵呵

          # re: 開始android的HelloWorld  回復  更多評論   

          2011-02-23 23:07 by penngo
          呵呵,一起學.
          主站蜘蛛池模板: 丹寨县| 自治县| 綦江县| 绥阳县| 嘉定区| 峨眉山市| 井研县| 香格里拉县| 湟源县| 青海省| 久治县| 米易县| 宁安市| 皮山县| 邵武市| 河西区| 灵川县| 调兵山市| 多伦县| 罗平县| 阿城市| 开平市| 武功县| 乌海市| 井研县| 永宁县| 馆陶县| 卢湾区| 远安县| 从化市| 大埔县| 罗平县| 革吉县| 双桥区| 鄢陵县| 湖州市| 平定县| 江城| 忻城县| 抚州市| 浮山县|