Android入門學習_Hello Word程序設計

Hello,World是咱們每學一門語言,第一個要寫得程序,今天我就從這開始。

       打開ECLIPSE,選擇 File > New > Project.>others>Andriod project在出現的對話框裏輸入 Project Name,Application Name,Package Name,Create Activity,選擇ANDROID1.5,點擊FINISH.

       項目就建完了,很簡單吧。出乎個人意料。java

       如今看看具體代碼文件,在左邊的package explorer,select project helloworld.android

       在src下打開HelloAndriod.java文件。app


java代碼:
  1. package eoe.demo;

  2. import android.app.Activity;
  3. import android.os.Bundle;

  4. public class HelloAndroid extends Activity {
  5. /** Called when the activity is first created. */
  6. //程序入口點
  7. @Override
  8. public void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.main);
  11. //設置顯示的UI,
  12. R.layout.main就是一個XML文件。
  13. }
  14. }
  15. /res/layout/main.XML內容以下
  16. <?xml version="1.0" encoding="utf-8"?>
  17. <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_;fill_parent"
  18. android:layout_height="fill_parent"
  19. android:text="@string/hello"/>
  20. //在strings.xml定義
  21. <?xml version="1.0" encoding="utf-8"?>
  22. //固定的
  23. xmlns:android=http://schemas.android.com/apk/res/android
  24. XML的NAMESPACE,每一格都必須有。
複製代碼

       android:layout_width
       android:layout_heightide


       當前VIEW的寬和高。fill_parent的含義在這個程序中是暫居佔據整個SCREEN。text 顯示的內容,這裏採用定義的常量表示。spa

    res/values/ strings.xmlcode


java代碼:
xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <string name="hello">Hello, Android! I am a string resource!</string>
  4. <string name="app_name">Hello, Android</string>
  5. </resources>

  6. //順便看一下R.JAVA

  7. package eoe.demo;
  8. public final class R {
  9. public static final class attr { }
  10. public static final class drawable {
  11. public static final int icon=0x7f020000;
  12. }
  13. public static final class layout {
  14. public static final int main=0x7f030000;
  15. }
  16. public static final class string {
  17. public static final int app_name=0x7f040001;
  18. public static final int hello=0x7f040000;
  19. }

  20. }
複製代碼
相關文章
相關標籤/搜索