posts - 8,  comments - 25,  trackbacks - 0

          Android的應用中有很多UI的設計都是比較固定的,比如很多應用都會有titlebar和tabbar。我這里就將自己工作過程中碰到的各種比較固定的UI組件的制作方法寫出來。
          titlebar(標題欄)的應用尤為廣泛,主要起到提示和導航的作用,組件里面涉及到的控件有ImageView和TextView(這里并不唯一,視你制作方法而定)。下面就來介紹我的做法,先貼上main.xml的代碼和效果圖。
          代碼如下:
           1 <?xml version="1.0" encoding="utf-8"?>
           2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           3     android:orientation="vertical"
           4     android:layout_width="fill_parent"
           5     android:layout_height="fill_parent"
           6     android:background="@drawable/background">
           7     
           8     <RelativeLayout android:layout_width="fill_parent"
           9         android:layout_height="wrap_content"
          10         android:background="@drawable/toolbar_background" >
          11         
          12         <RelativeLayout android:id="@+id/toolbar_left"
          13             android:layout_width="wrap_content" 
          14             android:layout_height="wrap_content"
          15             android:layout_alignParentLeft="true"
          16             android:layout_centerVertical="true"
          17             android:layout_marginLeft="10dip"
          18             android:clickable="true">
          19             <ImageView android:id="@+id/toolbar_left_image"
          20                 style="@style/toolbar_left_button_image"/>
          21             <TextView android:id="@+id/toolbar_left_text"
          22                 android:text="@string/toolbar_return" 
          23                 android:layout_alignTop="@id/toolbar_left_image"
          24                 android:layout_alignLeft="@id/toolbar_left_image"
          25                 style="@style/toolbar_left_button_text" />
          26         </RelativeLayout>
          27         
          28         <RelativeLayout android:layout_width="wrap_content"
          29             android:layout_height="wrap_content"
          30             android:layout_centerInParent="true">
          31             <TextView android:layout_width="wrap_content"
          32                 android:layout_height="wrap_content"
          33                 android:text="@string/toolbar_everydaytip"
          34                 style="@style/toolbar_text" />
          35         </RelativeLayout>
          36         
          37         <RelativeLayout android:id="@+id/toolbar_right"
          38             android:layout_width="wrap_content" 
          39             android:layout_height="wrap_content"
          40             android:layout_alignParentRight="true"
          41             android:layout_centerVertical="true"
          42             android:layout_marginRight="10dip"
          43             android:clickable="true">
          44             <ImageView android:id="@+id/toolbar_right_image"
          45                 style="@style/toolbar_right_button_image" />
          46             <TextView android:id="@+id/toolbar_right_text"
          47                 android:text="@string/toolbar_index" 
          48                 android:layout_alignTop="@id/toolbar_right_image"
          49                 android:layout_alignLeft="@id/toolbar_right_image"
          50                 style="@style/toolbar_right_button_text" />
          51         </RelativeLayout>
          52         
          53     </RelativeLayout>
          54
          55 </LinearLayout>
          附圖如下:

          這里主要用到了RelativeLayout來實現比較精細的布局控制
          posted on 2011-07-10 16:33 我是風之子 閱讀(5272) 評論(4)  編輯  收藏 所屬分類: 移動開發相關

          FeedBack:
          # re: Android常用UI之titlebar制作
          2011-07-10 23:31 | 步步為營
          很實用,這設計最初是iPhone用戶的習慣 :)  回復  更多評論
            
          # re: Android常用UI之titlebar制作
          2011-07-11 09:11 | 爆爆藍
          在android 里面完全沒必要照搬ipone的設計,因為androi有實體的返回鍵和主頁鍵  回復  更多評論
            
          # re: Android常用UI之titlebar制作
          2011-07-11 11:39 | 我是風之子
          @爆爆藍
          我這里的返回鍵和主頁鍵只是個例子,實際只是個跳轉按鈕;
          不過android的主頁鍵會離開程序的吧  回復  更多評論
            
          # re: Android常用UI之titlebar制作
          2013-09-24 21:42 | 4332weizi
          能不能把style也發出來啊……  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2011年7月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 加查县| 依兰县| 依安县| 宁河县| 七台河市| 石家庄市| 水城县| 三原县| 双城市| 上虞市| 湖北省| 邻水| 呈贡县| 鄄城县| 孟津县| 河源市| 沾化县| 邹城市| 富宁县| 杭锦旗| 浑源县| 肃南| 福泉市| 邛崃市| 五大连池市| 大港区| 贺兰县| 厦门市| 和静县| 泸定县| 五大连池市| 和龙市| 赞皇县| 建阳市| 金塔县| 平顺县| 大田县| 武宁县| 织金县| 施甸县| 西贡区|