1 / 59

Chapter 2 建構BMI 範例程式

Chapter 2 建構BMI 範例程式. 大綱. 建構 BMI 範例程式 建立新專案 UI 設計:相關工具、 LinearLayout 、 TextView 、 EditText 、 Button UI 資源統整及優化: string.xml 、 style.xml 等 進入 BMI 程式前: Activity 介紹、 AndroidManifest 相關參數介紹 BMI 程式:連結 UI 與控制 程式結構優化 Debug 版面配置介紹. 建立 BMI 新專案. BMI 程式畫面. 建立 BMI 專案. 建立 BMI 專案. 建立 BMI 專案.

whitley
Télécharger la présentation

Chapter 2 建構BMI 範例程式

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2 建構BMI 範例程式

  2. 大綱 建構BMI 範例程式 建立新專案 UI 設計:相關工具、LinearLayout、TextView、EditText、Button UI資源統整及優化:string.xml、style.xml等 進入BMI程式前:Activity介紹、AndroidManifest 相關參數介紹 BMI程式:連結UI與控制 程式結構優化 Debug 版面配置介紹

  3. 建立 BMI 新專案

  4. BMI程式畫面

  5. 建立BMI專案

  6. 建立BMI專案

  7. 建立BMI專案

  8. BMI UI 設計

  9. UI 設計 – Graphical Layout

  10. UI 設計 – Graphical Layout 若畫面有問題,至Window > Preferences > General > Editors > restore defaults

  11. UI 設計 – XML

  12. BMIUI分析 線性排版 LinearLayout 項目、結果、建議 TextView 輸入框 EditText 按鈕 Button

  13. 請完成以下版面

  14. View 常用屬性 所有元件都是繼承View id ex:@+id/test width、height fill_parent wrap_content 長度單位(px、dip) padding padding、paddingLeft、paddingTop 、paddingRight、paddingBottom

  15. View 常用屬性 layout_margin layout_marginLeft、layout_marginTop 、layout_marginRight 、layout_marginBottom visibility visible、invidible、gone background 資源 id (ex:@color/red)、RGB、ARGB layout_gravity left、right、top、bottom、center、 center_vertical、center_horizontal

  16. LinearLayout 線性排版 orientation vertical、horizontal gravity left、right、top、bottom、center、 center_vertical、center_horizontal

  17. TextView text 資源 id(ex:@string/test)、文字 textSize px、sp textColor 資源 id (ex:@color/red)、RGB、ARGB textStyle normal、bold、italic gravity singleLine ellipsize none、start、middle、end、marquee marqueeRepeatLimit

  18. EditText extends TextView hint 資源 id(ex:@string/test)、文字 textColorHint 資源 id (ex:@color/red)、RGB、ARGB inputType text(任何字元), textMultiLine, textEmailAddress, textPassword…

  19. Button extends TextView

  20. 請完成以下版面

  21. BMI UI資源統整及優化

  22. UI資源統整及優化 字串 strings.xml 顏色 colors.xml 樣式 styles.xml 自訂xml

  23. 抽離字串strings.xml @string/字串名稱

  24. 抽離顏色 @colors/顏色名稱

  25. 抽離樣式 @style/樣式名稱

  26. 自訂xml BMI 建議

  27. BMIUI

  28. 進入BMI程式前

  29. AndroidManifest

  30. AndroidManifest

  31. AndroidManifest package name APP主要識別 versionCode 整數,為主要版本編號識別,不會於APP介紹頁顯示 versionName 字串,為版本名稱,於APP介紹頁顯示

  32. AndroidManifest 使用者最低版本需求,10為android 2.3.3 APP定義標籤,主要結構包括Activity、Service等需定義在此標籤內 icon APP主要icon label APP主要顯示名稱

  33. AndroidManifest Activity定義標籤,即APP主要畫面,一個標籤代表一個Activity,沒有在application標籤中定義的Activity將無法呼叫 name Activity名稱,為路徑描述,若是在APPpackget name的package中,可以用 [.ActivityClassName] 表示,代表 [package.ActivityClassName ],其他package則需寫出完整路徑,如 [com.yzu.test.TestActivity] label 顯示於Activity上方標題列的名稱

  34. AndroidManifest intent-filter定義Activity的性質,包含進入此Activity的方式以及類別 action 為進入點,android.intent.action.MAIN,表示進入App時,此Activity將第一個執行顯示 category 類別定義,android.intent.category.LAUNCHER,表示此Activity,將顯示於Launcher的應用程式列表中

  35. Activity 具有生命週期 代表APP主要畫面 需在AndroidManifest.xml中設置

  36. Activity package資料夾位置 匯入相關的Class 程式主體,代表 [ 宣告一個公開的BMIActivity類別,此類別繼承Activity類別 ]

  37. Activity onCreate為Activity啟動初始化時第一個執行的Method,即Activity生命週期的起始點,而為了建立此APP專用的Activity,因此覆寫繼承自Activity類別的onCreate, @Override 表示此Method複寫父類別的Method Bundle savedInstanceState 當APP啟動、背景等待或關閉等狀態改變時,皆需要傳遞此參數,以維持APP運作,一般不需要任何改變

  38. Activity super為關鍵字,代表此類別的父類別Activity,因此這句的意思為執行父類別的onCreate,一般Method覆寫後將忽略原本父類別Method中的內容,但是在父類別ActivityonCreate中會呼叫所有Activity執行所需的Method,故在此需要先呼叫父類別的onCreateMethod,再繼續加入需要的內容

  39. Activity 執行setContentView設定Activity畫面,在此為引入R.layout.main設定檔,以此設定檔內容繪製Activity畫面,並與此layout連結

  40. Activity生命週期 Activity http://developer.android.com/reference/android/app/Activity.html

  41. 了解Activity生命週期運作 覆寫生命週期中的Method並以Log追蹤 android.util.Log Log.v(Tag,Mes) verbose黑色,以verbose為條件過濾時任何消息都會輸出 Log.d(Tag,Mes) debug藍色,以debug為條件過濾時d、i 、w、e都會輸出 Log.i(Tag,Mes) info綠色,以debug為條件過濾時i 、w、e都會輸出 Log.w(Tag,Mes) warning橘色,以debug為條件過濾時w、e都會輸出 Log.e(Tag,Mes) error紅色

  42. BMI 程式設計

  43. 識別Layout中的元件 將要控制的元件加上id android:id = ” @+id/名稱” android:id="@+id/ET_Height“ android:id="@+id/ET_Weight” android:id="@+id/B_Count” android:id="@+id/TV_Result“ android:id="@+id/TV_Advice"

  44. 程式撰寫

  45. 執行結果

  46. BMI 程式結構優化

  47. BMI 程式結構優化

  48. BMI 程式結構優化

  49. DDMS除錯

  50. Oops!

More Related