Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 高級開發 >> Android UI設計模板Dashboard及Action Bar的應用

Android UI設計模板Dashboard及Action Bar的應用

編輯:高級開發

Action bar及Dashboard能在大多數android程序項目中為用戶提供界面設計圖案。

Dashboard項目組已經開始著手於一個項目,以幫助開發者們更快地使他們的項目步入軌道。這一項目的目的是將可在不同UI模板上使用的代碼收集並整合起來。我以Google IO會議上的android應用程序為基礎,去掉冗余的代碼,以使這些精簡過的好用的部分更易於理解。

我在做的項目可以在下面的谷歌代碼網站中找到.

目前該項目只進行一項工作,其成果將同時作用於Dashboard及Action bar。

實施指南

實施指南

讓所有的android應用程序都能同時支持縱向及橫向顯示模式,這一點非常重要。盡管許多布局方案在編輯正確的前提下,都可以自動實現對縱向、橫向顯示模式的支持,但Dashboard所制作的布局還做不到這一點。為了保證這兩種模式下都具備充足的可用空間,我們需要編寫兩個單獨的布局XMLs。只要我們將相同的布局XML文件放入正確的文件夾並提交給android系統,系統框架將在運行時自動選擇合適的顯示方式。

支持不同方向下的不同布局的構架范例

支持不同方向下的不同布局的構架范例

縱向布局XML代碼

  1. dashboard.XML:
  2. <?XML version="1.0" encoding="utf-8"?>
  3. <!--
  4. Copyright 2010 Google Inc.
  5. Licensed under the apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <LinearLayout XMLns:android="http://schemas.android.com/apk/res/android"
  16. android:id="@+id/home_root"
  17. android:orIEntation="vertical"
  18. android:layout_width="fill_parent"
  19. android:layout_height="fill_parent">
  20. <LinearLayout style="@style/TitleBar">
  21. <ImageVIEw style="@style/TitleBarLogo"
  22. android:contentDescription="@string/description_logo"
  23. android:src="@drawable/title_logo" />
  24. <VIEw style="@style/TitleBarSpring" />
  25. <ImageVIEw style="@style/TitleBarSeparator" />
  26. <ImageButton style="@style/TitleBarAction"
  27. android:id="@+id/btn_title_refresh"
  28. android:contentDescription="@string/description_refresh"
  29. android:src="@drawable/ic_title_refresh"
  30. android:onClick="onActionBarButtonClick" />
  31. <ProgressBar style="@style/TitleBarProgressIndicator"
  32. android:id="@+id/title_refresh_progress"
  33. android:visibility="gone" />
  34. <ImageVIEw style="@style/TitleBarSeparator" />
  35. <ImageButton style="@style/TitleBarAction"
  36. android:contentDescription="@string/description_search"
  37. android:src="@drawable/ic_title_search"
  38. android:onClick="onActionBarButtonClick" />
  39. </LinearLayout>
  40. <LinearLayout
  41. android:orIEntation="vertical"
  42. android:layout_width="fill_parent"
  43. android:layout_height="wrap_content"
  44. android:layout_weight="1"
  45. android:padding="6dip">
  46. <LinearLayout
  47. android:orIEntation="horizontal"
  48. android:layout_width="fill_parent"
  49. android:layout_height="wrap_content"
  50. android:layout_weight="1">
  51. <Button android:id="@+id/action_one_button"
  52. style="@style/HomeButton"
  53. android:onClick="onActionOneClick"
  54. android:text="@string/dashboard_action"
  55. android:drawableTop="@drawable/dashboard_button_selector"/>
  56. <Button android:id="@+id/action_two_button"
  57. style="@style/HomeButton"
  58. android:onClick="onActionTwoClick"
  59. android:text="@string/dashboard_action"
  60. android:drawableTop="@drawable/dashboard_button_selector"/>
  61. </LinearLayout>
  62. <LinearLayout
  63. android:orIEntation="horizontal"
  64. android:layout_width="fill_parent"
  65. android:layout_height="wrap_content"
  66. android:layout_weight="1">
  67. <Button android:id="@+id/action_three_button"
  68. style="@style/HomeButton"
  69. android:onClick="onActionThreeClick"
  70. android:text="@string/dashboard_action"
  71. android:drawableTop="@drawable/dashboard_button_selector"/>
  72. <Button android:id="@+id/action_four_button"
  73. style="@style/HomeButton"
  74. android:onClick="onActionFourClick"
  75. android:text="@string/dashboard_action"
  76. android:drawableTop="@drawable/dashboard_button_selector"/>
  77. </LinearLayout>
  78. <LinearLayout
  79. android:orIEntation="horizontal"
  80. android:layout_width="fill_parent"
  81. android:layout_height="wrap_content"
  82. android:layout_weight="1">
  83. <Button android:id="@+id/action_five_button"
  84. style="@style/HomeButton"
  85. android:onClick="onActionFiveClick"
  86. android:text="@string/dashboard_action"
  87. android:drawableTop="@drawable/dashboard_button_selector"/>
  88. <Button android:id="@+id/action_six_button"
  89. style="@style/HomeButton"
  90. android:onClick="onActionSixClick"
  91. android:text="@string/dashboard_action"
  92. android:drawableTop="@drawable/dashboard_button_selector"/>
  93. </LinearLayout>
  94. </LinearLayout>
  95. <LinearLayout
  96. android:id="@+id/now_playing_loading"
  97. android:layout_width="fill_parent"
  98. android:layout_height="@dimen/now_playing_height"
  99. android:orIEntation="horizontal"
  100. android:background="#eee"
  101. android:gravity="center">
  102. <ProgressBar
  103. style="?android:attr/progressBarStyleSmall"
  104. android:layout_width="wrap_content"
  105. android:layout_height="wrap_content"
  106. android:paddingRight="6dip"
  107. android:indeterminate="true"/>
  108. <TextVIEw
  109. android:layout_width="wrap_content"
  110. android:layout_height="wrap_content"
  111. android:textSize="@dimen/text_size_small"
  112. android:text="@string/now_playing_loading"/>
  113. </LinearLayout>
  114. </LinearLayout>

浏覽模式XML代碼

  1. dashboard.XML:
  2. <?XML version="1.0" encoding="utf-8"?>
  3. <!--
  4. Copyright 2010 Google Inc.
  5. Licensed under the apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <LinearLayout XMLns:android="http://schemas.android.com/apk/res/android"
  16. android:id="@+id/home_root"
  17. android:orIEntation="vertical"
  18. android:layout_width="fill_parent"
  19. android:layout_height="fill_parent">
  20. <LinearLayout style="@style/TitleBar">
  21. <ImageVIEw style="@style/TitleBarLogo"
  22. android:src="@drawable/title_logo" />
  23. <VIEw style="@style/TitleBarSpring" />
  24. <ImageVIEw style="@style/TitleBarSeparator" />
  25. <ImageButton style="@style/TitleBarAction"
  26. android:id="@+id/btn_title_refresh"
  27. android:src="@drawable/ic_title_refresh"
  28. android:onClick="onActionBarButtonClick" />
  29. <ProgressBar style="@style/TitleBarProgressIndicator"
  30. android:id="@+id/title_refresh_progress"
  31. android:visibility="gone" />
  32. <ImageVIEw style="@style/TitleBarSeparator" />
  33. <ImageButton style="@style/TitleBarAction"
  34. android:src="@drawable/ic_title_search"
  35. android:onClick="onActionBarButtonClick" />
  36. </LinearLayout>
  37. <LinearLayout
  38. android:orIEntation="vertical"
  39. android:layout_width="fill_parent"
  40. android:layout_height="wrap_content"
  41. android:layout_weight="1"
  42. android:padding="6dip">
  43. <LinearLayout
  44. android:orIEntation="horizontal"
  45. android:layout_width="fill_parent"
  46. android:layout_height="wrap_content"
  47. android:layout_weight="1">
  48. <Button android:id="@+id/action_one_button"
  49. style="@style/HomeButton"
  50. android:onClick="onActionOneClick"
  51. android:text="@string/dashboard_action"
  52. android:drawableTop="@drawable/dashboard_button_selector"/>
  53. <Button android:id="@+id/action_two_button"
  54. style="@style/HomeButton"
  55. android:onClick="onActionTwoClick"
  56. android:text="@string/dashboard_action"
  57. android:drawableTop="@drawable/dashboard_button_selector"/>
  58. <Button android:id="@+id/action_three_button"
  59. style="@style/HomeButton"
  60. android:onClick="onActionThreeClick"
  61. android:text="@string/dashboard_action"
  62. android:drawableTop="@drawable/dashboard_button_selector"/>
  63. </LinearLayout>
  64. <LinearLayout
  65. android:orIEntation="horizontal"
  66. android:layout_width="fill_parent"
  67. android:layout_height="wrap_content"
  68. android:layout_weight="1">
  69. <Button android:id="@+id/action_four_button"
  70. style="@style/HomeButton"
  71. android:onClick="onActionFourClick"
  72. android:text="@string/dashboard_action"
  73. android:drawableTop="@drawable/dashboard_button_selector"/>
  74. <Button android:id="@+id/action_five_button"
  75. style="@style/HomeButton"
  76. android:onClick="onActionFiveClick"
  77. android:text="@string/dashboard_action"
  78. android:drawableTop="@drawable/dashboard_button_selector"/>
  79. <Button android:id="@+id/action_six_button"
  80. style="@style/HomeButton"
  81. android:onClick="onActionSixClick"
  82. android:text="@string/dashboard_action"
  83. android:drawableTop="@drawable/dashboard_button_selector"/>
  84. </LinearLayout>
  85. </LinearLayout>
  86. </LinearLayout>

其它實用項目

在android系統中另有許多實用項目,以使開發者可以很容易地獲取兼容性許可。

iOSched - Google IO app by Google

這個項目試圖提供一個在應用程序上實現Dashboard及Action bar用戶設計模塊的完整范例,這是個相當大的工程。有鑒於此,如果你只需要兼容Dashboard或Action bar工具的設計成果,我建議你使用android-ui-patterns(android用戶模塊工具)。

GreenDroid library

源自網絡的項目目標列表

◆避免在重復拷貝相同的代碼上浪費時間

◆嘗試使android上的不同應用程序更加相似

◆幫助開發者構建功能強大的應用程序

◆充分利用android系統框架的功能

◆盡可能多地使用XML

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved