Android UI设计模板Dashboard及Action Bar的应用

原创
移动开发 Android
前面我们已经介绍了Dashboard,本文我们将介绍Action bar及Dashboard能在大多数Android程序项目中为用户提供界面设计图案。

【51CTO译文】Action bar及Dashboard能在大多数Android程序项目中为用户提供界面设计图案。

Dashboard项目组已经开始着手于一个项目,以帮助开发者们更快地使他们的项目步入轨道。这一项目的目的是将可在不同UI模板上使用的代码收集并整合起来。我以Google IO会议上的Android应用程序为基础,去掉冗余的代码,以使这些精简过的好用的部分更易于理解。

我在做的项目可以在下面的谷歌代码网站中找到.

目前该项目只进行一项工作,其成果将同时作用于Dashboard及Action bar。

实施指南

实施指南

让所有的Android应用程序都能同时支持纵向及横向显示模式,这一点非常重要。尽管许多布局方案在编辑正确的前提下,都可以自动实现对纵向、横向显示模式的支持,但Dashboard所制作的布局还做不到这一点。为了保证这两种模式下都具备充足的可用空间,我们需要编写两个单独的布局XMLs。只要我们将相同的布局XML文件放入正确的文件夹并提交给Android系统,系统框架将在运行时自动选择合适的显示方式。

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

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

纵向布局XML代码

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

浏览模式XML代码

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

其它实用项目

在Android系统中另有许多实用项目,以使开发者可以很容易地获取兼容性许可。

iosched - Google IO app by Google

这个项目试图提供一个在应用程序上实现Dashboard及Action bar用户设计模块的完整范例,这是个相当大的工程。有鉴于此,如果你只需要兼容Dashboard或Action bar工具的设计成果,我建议你使用android-ui-patterns(android用户模块工具)。

GreenDroid library

源自网络的项目目标列表

◆避免在重复拷贝相同的代码上浪费时间

◆尝试使Android上的不同应用程序更加相似

◆帮助开发者构建功能强大的应用程序

◆充分利用Android系统框架的功能

◆尽可能多地使用XML

原文地址

【51CTO译稿,非经授权谢绝转载,合作媒体转载请注明原文出处、作者及51CTO译稿和译者!】

【编辑推荐】

  1. Windows Phone 7 免费线下培训火热报名中
  2. Dashboard Android用户自定义UI设计模板
  3. Android用户界面设计模板Dashboard产品展示
  4. Android用户界面设计模板Dashboard反例展示 
  5. Android用户界面OmniGraffle设计模板及下载
  6. Android UI自定义设计模板Dashboard
责任编辑:佚名 来源: 51CTO
相关推荐

2011-03-02 10:24:23

DashboardAndroid用户界面设计模板

2011-11-04 16:49:26

Action BarAndroid

2011-03-02 14:03:02

DashboardAndroid用户界面反例模板

2011-03-02 10:49:42

DashboardAndroid用户界面设计模板

2011-03-02 13:16:15

OmniGraffleAndroid用户界面

2011-05-28 15:14:06

设计技巧UIAndroid

2011-06-07 09:15:35

参数设置屏幕UI设计

2011-06-01 16:12:11

Android UI

2012-03-01 20:14:25

Android UI

2011-05-28 12:19:33

设计技巧UIAndroid

2013-07-23 16:33:27

Android视觉效果UI

2017-03-10 18:29:17

Androidfreemarker应用

2018-01-01 20:56:43

AndroidUIAPI

2011-03-25 15:08:00

UI设计

2011-12-29 21:22:29

Windows Pho

2011-09-14 10:29:23

Android UI设

2010-09-14 09:38:48

AndroidUI

2010-02-04 13:30:49

Android UI元

2011-02-16 14:15:58

FringAndroid应用iOS应用

2014-07-08 12:26:24

Android LUI设计
点赞
收藏

51CTO技术栈公众号