The NoteBook of EricKong

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks

          在LinearLayout中,如果將其定位方向設為橫向排列:android:orientation="horizontal",那么這個布局中的控件將自左向右排列。

          但有時會有這樣的情況:行的左邊有兩個控制的同時,行的右邊也有一個控制。

          如圖:

          這怎么處理呢?

          我們可以將右邊的控件放在另一個LinearLayout中,同時將其對齊方式設為右對齊:android:gravity="right",還有一點,這個LinearLayout的寬度設為充滿父控件: android:layout_width="fill_parent"。這樣就行了。

          完整的XML代碼如下:

          Xml代碼  收藏代碼
          1. <?xml version="1.0" encoding="utf-8"?>  
          2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
          3.     android:layout_width="fill_parent"  
          4.     android:layout_height="fill_parent"  
          5.     android:background="@drawable/bg"  
          6.     android:orientation="horizontal" >  
          7.   
          8.     <TextView  
          9.         android:layout_width="wrap_content"  
          10.         android:layout_height="wrap_content"  
          11.         android:text="左邊1" />  
          12.   
          13.     <TextView  
          14.         android:layout_width="wrap_content"  
          15.         android:layout_height="wrap_content"  
          16.         android:text="左邊2" />  
          17.     <!-- 將TextView包在另一個LinearLayout中  
          18.          注意android:layout_width和android:gravity這兩個屬性  
          19.      -->  
          20.     <LinearLayout  
          21.         android:layout_width="fill_parent"  
          22.         android:layout_height="wrap_content"  
          23.         android:gravity="right" >  
          24.   
          25.         <TextView  
          26.             android:layout_width="wrap_content"  
          27.             android:layout_height="wrap_content"  
          28.             android:layout_marginRight="10dp"  
          29.             android:text="右邊" />  
          30.     </LinearLayout>  
          31.   
          32. </LinearLayout>  
          posted on 2014-12-16 15:42 Eric_jiang 閱讀(337) 評論(0)  編輯  收藏 所屬分類: Android
          主站蜘蛛池模板: 安图县| 廊坊市| 旌德县| 平山县| 余江县| 呼伦贝尔市| 青川县| 唐河县| 宝兴县| 油尖旺区| 克东县| 吉林市| 奉贤区| 天台县| 萍乡市| 安溪县| 宝山区| 阿巴嘎旗| 高尔夫| 牟定县| 项城市| 广德县| 元氏县| 广州市| 四子王旗| 绥中县| 共和县| 汝州市| 邯郸市| 从化市| 洪洞县| 高密市| 台湾省| 阳原县| 丹寨县| 游戏| 鄂州市| 东安县| 钟山县| 灵丘县| 玉山县|