編輯:高級開發
Dashboard項目組已經開始著手於一個項目,以幫助開發者們更快地使他們的項目步入軌道。這一項目的目的是將可在不同UI模板上使用的代碼收集並整合起來。我以Google IO會議上的android應用程序為基礎,去掉冗余的代碼,以使這些精簡過的好用的部分更易於理解。
我在做的項目可以在下面的谷歌代碼網站中找到.
目前該項目只進行一項工作,其成果將同時作用於Dashboard及Action bar。
實施指南
讓所有的android應用程序都能同時支持縱向及橫向顯示模式,這一點非常重要。盡管許多布局方案在編輯正確的前提下,都可以自動實現對縱向、橫向顯示模式的支持,但Dashboard所制作的布局還做不到這一點。為了保證這兩種模式下都具備充足的可用空間,我們需要編寫兩個單獨的布局XMLs。只要我們將相同的布局XML文件放入正確的文件夾並提交給android系統,系統框架將在運行時自動選擇合適的顯示方式。
支持不同方向下的不同布局的構架范例
縱向布局XML代碼
- dashboard.XML:
- <?XML version="1.0" encoding="utf-8"?>
- <!--
- Copyright 2010 Google Inc.
- Licensed under the apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <LinearLayout XMLns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/home_root"
- android:orIEntation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <LinearLayout style="@style/TitleBar">
- <ImageVIEw style="@style/TitleBarLogo"
- android:contentDescription="@string/description_logo"
- android:src="@drawable/title_logo" />
- <VIEw style="@style/TitleBarSpring" />
- <ImageVIEw style="@style/TitleBarSeparator" />
- <ImageButton style="@style/TitleBarAction"
- android:id="@+id/btn_title_refresh"
- android:contentDescription="@string/description_refresh"
- android:src="@drawable/ic_title_refresh"
- android:onClick="onActionBarButtonClick" />
- <ProgressBar style="@style/TitleBarProgressIndicator"
- android:id="@+id/title_refresh_progress"
- android:visibility="gone" />
- <ImageVIEw style="@style/TitleBarSeparator" />
- <ImageButton style="@style/TitleBarAction"
- android:contentDescription="@string/description_search"
- android:src="@drawable/ic_title_search"
- android:onClick="onActionBarButtonClick" />
- </LinearLayout>
- <LinearLayout
- android:orIEntation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:padding="6dip">
- <LinearLayout
- android:orIEntation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- <Button android:id="@+id/action_one_button"
- style="@style/HomeButton"
- android:onClick="onActionOneClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- <Button android:id="@+id/action_two_button"
- style="@style/HomeButton"
- android:onClick="onActionTwoClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- </LinearLayout>
- <LinearLayout
- android:orIEntation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- <Button android:id="@+id/action_three_button"
- style="@style/HomeButton"
- android:onClick="onActionThreeClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- <Button android:id="@+id/action_four_button"
- style="@style/HomeButton"
- android:onClick="onActionFourClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- </LinearLayout>
- <LinearLayout
- android:orIEntation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- <Button android:id="@+id/action_five_button"
- style="@style/HomeButton"
- android:onClick="onActionFiveClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- <Button android:id="@+id/action_six_button"
- style="@style/HomeButton"
- android:onClick="onActionSixClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- </LinearLayout>
- </LinearLayout>
- <LinearLayout
- android:id="@+id/now_playing_loading"
- android:layout_width="fill_parent"
- android:layout_height="@dimen/now_playing_height"
- android:orIEntation="horizontal"
- android:background="#eee"
- android:gravity="center">
- <ProgressBar
- style="?android:attr/progressBarStyleSmall"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingRight="6dip"
- android:indeterminate="true"/>
- <TextVIEw
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="@dimen/text_size_small"
- android:text="@string/now_playing_loading"/>
- </LinearLayout>
- </LinearLayout>
浏覽模式XML代碼
- dashboard.XML:
- <?XML version="1.0" encoding="utf-8"?>
- <!--
- Copyright 2010 Google Inc.
- Licensed under the apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <LinearLayout XMLns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/home_root"
- android:orIEntation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <LinearLayout style="@style/TitleBar">
- <ImageVIEw style="@style/TitleBarLogo"
- android:src="@drawable/title_logo" />
- <VIEw style="@style/TitleBarSpring" />
- <ImageVIEw style="@style/TitleBarSeparator" />
- <ImageButton style="@style/TitleBarAction"
- android:id="@+id/btn_title_refresh"
- android:src="@drawable/ic_title_refresh"
- android:onClick="onActionBarButtonClick" />
- <ProgressBar style="@style/TitleBarProgressIndicator"
- android:id="@+id/title_refresh_progress"
- android:visibility="gone" />
- <ImageVIEw style="@style/TitleBarSeparator" />
- <ImageButton style="@style/TitleBarAction"
- android:src="@drawable/ic_title_search"
- android:onClick="onActionBarButtonClick" />
- </LinearLayout>
- <LinearLayout
- android:orIEntation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:padding="6dip">
- <LinearLayout
- android:orIEntation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- <Button android:id="@+id/action_one_button"
- style="@style/HomeButton"
- android:onClick="onActionOneClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- <Button android:id="@+id/action_two_button"
- style="@style/HomeButton"
- android:onClick="onActionTwoClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- <Button android:id="@+id/action_three_button"
- style="@style/HomeButton"
- android:onClick="onActionThreeClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- </LinearLayout>
- <LinearLayout
- android:orIEntation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- <Button android:id="@+id/action_four_button"
- style="@style/HomeButton"
- android:onClick="onActionFourClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- <Button android:id="@+id/action_five_button"
- style="@style/HomeButton"
- android:onClick="onActionFiveClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- <Button android:id="@+id/action_six_button"
- style="@style/HomeButton"
- android:onClick="onActionSixClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- </LinearLayout>
- </LinearLayout>
- </LinearLayout>
其它實用項目
在android系統中另有許多實用項目,以使開發者可以很容易地獲取兼容性許可。
iOSched - Google IO app by Google
這個項目試圖提供一個在應用程序上實現Dashboard及Action bar用戶設計模塊的完整范例,這是個相當大的工程。有鑒於此,如果你只需要兼容Dashboard或Action bar工具的設計成果,我建議你使用android-ui-patterns(android用戶模塊工具)。
GreenDroid library
源自網絡的項目目標列表
◆避免在重復拷貝相同的代碼上浪費時間
◆嘗試使android上的不同應用程序更加相似
◆幫助開發者構建功能強大的應用程序
◆充分利用android系統框架的功能
◆盡可能多地使用XML
創建一個新項目是很簡單的,只要你安裝了Eclipse插件,並且你的Eclipse軟件版本在3.2或3.3,你就可以開始開發了。 首先, 看一下要創建Hello, Wo
內容提供程序(Provider)組件從一個應用到其他請求提供數據。通過 ContentResolver 類的方法這樣的請求處理。內容提供程序使用不同的方式來存儲
Google推出的android應用手機通過與運營商、設備制造商、開發商和其他有關各方結成深層次的合作伙伴關系,但同顯而易見的,是手機具有便攜性,24小時隨身相伴性和及
有以下兩種方式來使用 Android 設備發送短信:使用 SmsManager 發送短信使用內置 Intent 發送短信使用SmsManager 發送短信Sms