posts - 59, comments - 244, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

开始android的HelloWorld

Posted on 2011-02-23 00:44 penngo 阅读(2923) 评论(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
呵呵,一起学.

只有注册用户登录后才能发表评论。


网站导航: