掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
【譯文】Action Bar及Dashboard能在大多數(shù)Android程序項目中為用戶提供界面設(shè)計圖案。

創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供雄縣網(wǎng)站建設(shè)、雄縣做網(wǎng)站、雄縣網(wǎng)站設(shè)計、雄縣網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、雄縣企業(yè)網(wǎng)站模板建站服務(wù),十載雄縣做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
Dashboard項目組已經(jīng)開始著手于一個項目,以幫助開發(fā)者們更快地使他們的項目步入軌道。這一項目的目的是將可在不同UI模板上使用的代碼收集并整合起來。我以Google IO會議上的Android應(yīng)用程序為基礎(chǔ),去掉冗余的代碼,以使這些精簡過的好用的部分更易于理解。
我在做的項目可以在下面的谷歌代碼網(wǎng)站中找到.
目前該項目只進(jìn)行一項工作,其成果將同時作用于Dashboard及Action bar。
實施指南
讓所有的Android應(yīng)用程序都能同時支持縱向及橫向顯示模式,這一點非常重要。盡管許多布局方案在編輯正確的前提下,都可以自動實現(xiàn)對縱向、橫向顯示模式的支持,但Dashboard所制作的布局還做不到這一點。為了保證這兩種模式下都具備充足的可用空間,我們需要編寫兩個單獨的布局XMLs。只要我們將相同的布局XML文件放入正確的文件夾并提交給Android系統(tǒng),系統(tǒng)框架將在運行時自動選擇合適的顯示方式。
支持不同方向下的不同布局的構(gòu)架范例
縱向布局XML代碼
- dashboard.xml:
- android:id="@+id/home_root"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- android:contentDescription="@string/description_logo"
- android:src="@drawable/title_logo" />
- android:id="@+id/btn_title_refresh"
- android:contentDescription="@string/description_refresh"
- android:src="@drawable/ic_title_refresh"
- android:onClick="onActionBarButtonClick" />
- android:id="@+id/title_refresh_progress"
- android:visibility="gone" />
- android:contentDescription="@string/description_search"
- android:src="@drawable/ic_title_search"
- android:onClick="onActionBarButtonClick" />
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:padding="6dip">
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- style="@style/HomeButton"
- android:onClick="onActionThreeClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- style="@style/HomeButton"
- android:onClick="onActionFourClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- style="@style/HomeButton"
- android:onClick="onActionFiveClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- style="@style/HomeButton"
- android:onClick="onActionSixClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- 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">
- style="?android:attr/progressBarStyleSmall"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingRight="6dip"
- android:indeterminate="true"/>
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="@dimen/text_size_small"
- android:text="@string/now_playing_loading"/>
瀏覽模式XML代碼
- dashboard.xml:
- android:id="@+id/home_root"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- android:src="@drawable/title_logo" />
- android:id="@+id/btn_title_refresh"
- android:src="@drawable/ic_title_refresh"
- android:onClick="onActionBarButtonClick" />
- android:id="@+id/title_refresh_progress"
- android:visibility="gone" />
- android:src="@drawable/ic_title_search"
- android:onClick="onActionBarButtonClick" />
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:padding="6dip">
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- style="@style/HomeButton"
- android:onClick="onActionOneClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- style="@style/HomeButton"
- android:onClick="onActionTwoClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- style="@style/HomeButton"
- android:onClick="onActionThreeClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- style="@style/HomeButton"
- android:onClick="onActionFourClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- style="@style/HomeButton"
- android:onClick="onActionFiveClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
- style="@style/HomeButton"
- android:onClick="onActionSixClick"
- android:text="@string/dashboard_action"
- android:drawableTop="@drawable/dashboard_button_selector"/>
其它實用項目
在Android系統(tǒng)中另有許多實用項目,以使開發(fā)者可以很容易地獲取兼容性許可。
iosched - Google IO app by Google
這個項目試圖提供一個在應(yīng)用程序上實現(xiàn)Dashboard及Action bar用戶設(shè)計模塊的完整范例,這是個相當(dāng)大的工程。有鑒于此,如果你只需要兼容Dashboard或Action bar工具的設(shè)計成果,我建議你使用android-ui-patterns(android用戶模塊工具)。
GreenDroid library
源自網(wǎng)絡(luò)的項目目標(biāo)列表
◆避免在重復(fù)拷貝相同的代碼上浪費時間
◆嘗試使Android上的不同應(yīng)用程序更加相似
◆幫助開發(fā)者構(gòu)建功能強大的應(yīng)用程序
◆充分利用Android系統(tǒng)框架的功能
◆盡可能多地使用XML
原文地址
【譯稿,非經(jīng)授權(quán)謝絕轉(zhuǎn)載,合作媒體轉(zhuǎn)載請注明原文出處、作者及譯稿和譯者!】

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流