The NoteBook of EricKong

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks

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

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

          如圖:

          這怎么處理呢?

          我們可以將右邊的控件放在另一個LinearLayout中,同時將其對齊方式設(shè)為右對齊:android:gravity="right",還有一點(diǎn),這個LinearLayout的寬度設(shè)為充滿父控件: 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 閱讀(342) 評論(0)  編輯  收藏 所屬分類: Android
          主站蜘蛛池模板: 玉门市| 岳普湖县| 汉川市| 芮城县| 永靖县| 宁津县| 神池县| 积石山| 秦皇岛市| 长白| 台北县| 汤阴县| 南靖县| 施甸县| 桦川县| 苍南县| 邢台市| 杨浦区| 石狮市| 佳木斯市| 乳山市| 客服| 长兴县| 闻喜县| 县级市| 荔浦县| 枣阳市| 丰镇市| 北辰区| 韶山市| 睢宁县| 麻栗坡县| 双鸭山市| 达州市| 永修县| 稻城县| 芷江| 和林格尔县| 吉安市| 通海县| 伊通|