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

          開始android的HelloWorld

          Posted on 2011-02-23 00:44 penngo 閱讀(2938) 評論(2)  編輯  收藏 所屬分類: android
          android很火,也來學(xué)習(xí)下,上段時間上它官網(wǎng)(官網(wǎng)的訪問不了,只能訪問http://androidappdocs-staging.appspot.com/sdk/index.html)把android-sdk_r09-windows.zip下了回來,本來以為下了這個就能開始寫helloWorld,點知里面根本沒有開發(fā)的SDK和相關(guān)的開發(fā)工具,通過這地址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描述語言在桌面應(yīng)用將會更廣泛,在PB、Delphi、VC、VB年代,根據(jù)還未聽過有XML UI,不過HTML在BS的應(yīng)用倒是讓所有人如雷貫耳,哈哈。android的XML UI與QT相比,還弱了點,因為QML支持js,不知哈時候,android能支持js,不過寫這篇文章的前一天剛好看到Qt for Android (Alpha) 發(fā)布新聞,就是不知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還不熟悉,暫寫這么多記錄下來,有空再繼續(xù)學(xué)習(xí)。


          評論

          # re: 開始android的HelloWorld  回復(fù)  更多評論   

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

          # re: 開始android的HelloWorld  回復(fù)  更多評論   

          2011-02-23 23:07 by penngo
          呵呵,一起學(xué).

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 诸暨市| 香河县| 视频| 高雄市| 静海县| 仁怀市| 平顶山市| 普兰店市| 平安县| 牟定县| 襄汾县| 南宫市| 涞水县| 深泽县| 莫力| 高陵县| 贡觉县| 锦屏县| 浏阳市| 始兴县| 涟源市| 绩溪县| 塔河县| 淳安县| 依兰县| 招远市| 竹北市| 镇平县| 阿尔山市| 平远县| 天峻县| 日照市| 永登县| 庄河市| 深水埗区| 望奎县| 靖安县| 德格县| 白玉县| 新龙县| 张北县|