Android開發深入淺出一

 

                         不管是學習一門語言還是學習一個框架,我們都需要了解它的歷史背景,今天就讓我來和大家分享一下我對於Android的學習經驗吧:

  學習目標:Android的今生和前世                  Android的環境搭建                 HelloWorld案例                 Android的基本程序分析

                   Android的前世和今生       

                          2007年9月發佈第一個版本,一整套免費的手機軟件開發系統,operating system(操作系統),middleware(中間件),key mobile applications(關鍵的手機應用)

  最初由Android公司開發後被google收購,現在又Open Handset Alliance開發手機聯盟維護

  特點:開發性,所有的應用時平等的,應用間無界限,快速方便的應用開發

    在這裏分享一下別人對於手機平臺的感覺:

            手機平臺的戰國時代:3G,4G  ---- 移動互聯網的威力

                                           nokia    Iphone     Android  blackBerry    WP7   亂亂亂

                                            nokia   ---------------英雄遲暮

                                           Iphone   --------------偉大的領路人 叢矢之的

                                           Android    -----------Google偉大公司的跟風之作

                                           blackBerry  ----------獨行俠

                                           WP7    ----------------微軟能否挺起來的希望

           戰火的蔓延

                         Iphone Ipad            iTunes 音樂在線商店         AppStore應用在線商店     iCloud雲服務

             手機開發延伸  -------平板應用      總稱移動應用

       

            Android的獨特性 

                    Application Framework      Dalvik虛擬機          基於開源項目webKit引擎的瀏覽器

                    優化的圖形處理---通用的2D圖形庫以及基於OpenGL ES的3D圖形支持

                    SQLite數據庫     

                   多媒體支持 (MPEG4,H.264,MP3,AAC,AMR,JPG,PNG,GIF)

                     Bluetooth,EDGE,3G,and WiFi(handware dependent)

                   相機,GPS,羅盤,加速度計,重力感應

                    豐富的開發環境支持,模擬器,調試工具,ADT插件

      Android體系:applications和application Framework基於封裝好的JAVA,而最底層是Linux kernel基於語言是C/彙編

  

       對於Android的環境搭建在這裏我就不做介紹了,在網上有大量的文檔可以供大家查看,對於Android項目工程我也不做解釋,以下我只對R.java文件進行討論

     

               R.java文件時項目自動生成的,不可修改的文件,其中定義了項目中       所有資源索引

  public final class R{

             public static final class attr{

             }

             public static final class drawable{

                 public static final int icon=0x7f020000;

               }

               public static final class layout{

                     //這裏的layout就是res文件夾中的layout文件,main就是指的main.xml文件

                      public static final int main=0x7f030000;

               }

               public static final class string{

                        public static final int app_name=0x7f040001;

                         public static final int hell0=0x7f040000;

               }

}

    main.xml文件

 

                  如果你的程序由多屏內容組成,你就要在layout文件夾中定義多個xml文件以規定每一屏要顯示的內容
                 想想這樣做的好處?視圖與業務邏輯代碼的解耦
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  //線性佈局
mainl.xml   //文件定義了在一個屏幕中顯示什麼內容
xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"           //佈局寬度佔滿整個父節點即屏幕寬度
    android:layout_height="fill_parent"
    >
<TextView  //文本視圖框
    android:layout_width="fill_parent"    //文本框寬度填充整個父節點
    android:layout_height="wrap_content" //文本框高度適合內容
    android:text="@string/hello"//文本框顯示的內容是string.xml文件中hello鍵對應的值
    />
</LinearLayout>

 

              

     string.xml文件                

              程序中用到的所有字符定義在string.xml文件中
              這裏也應用了顯示內容與業務邏輯解耦的思想,方便國際化(後面介紹)
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">
   //把這裏改成中文試試看
       Hello World, HelloworldActivity!
    </string>
    <string name="app_name">Helloworld</string>
</resources>

 

       androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="huao.android.helloworld"//指定Android應用的包名
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />//最小支持的版本
    <application android:icon="@drawable/icon" //應用程序的圖標
        android:label="@string/app_name">   //應用程序的標籤名
        <activity android:name=".HelloworldActivity"        //定義一個Activity並指明類名
                  android:label="@string/app_name">         //指定該Activity在標籤欄顯示的字符
            <intent-filter>
                  指定該Activity是程序的入口
                <action android:name="android.intent.action.MAIN" />
                         指定加載該應用時運行該Activity
               <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

 

         今天對於Android開發就討論到這裏,下次將進一步的對Android進行討論

 

 

 

 

 

 

               

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章