2013-04-10 67 views
-3

下面是我的佈局XML代碼:如何讓佈局具有相同的高度?

 <LinearLayout 
      android:id="@+id/c" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 

      <RelativeLayout 
       android:id="@+id/a" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:orientation="vertical" > 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/b" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:orientation="vertical" > 
      </RelativeLayout> 
     </LinearLayout> 

我有2 RelativeLayout的,A和B,在LinearLayout中℃。
a和b可以有不同的高度。
我想使兩個RelativeLayout具有最高的相同高度。
我該如何實現它?

回答

2

把財產layout_weightsum = 2的布板 添加layout_weight爲1的佈局A,B和刪除layout_height屬性的a,b

1

嘗試

<LinearLayout 
     android:id="@+id/c" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:weightSum="2" > 

     <RelativeLayout 
     android:id="@+id/a" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/b" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" > 
    </RelativeLayout> 
    </LinearLayout> 

希望其幫助

1
  1. 將父母LinearLayout身高改爲match_parent。給予wrap_content將修復LinearLayout高度以適應其子視圖的大小。

  2. 更改RelativeLayout高度至0dip

+0

但我想的LinearLayout高度爲2 * MAX(A,B)。 – brian 2013-04-10 07:17:07

1

試試這個,它會自動下發的對兒童的佈局相同的空間。

<LinearLayout 

      android:id="@+id/c" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" > 

      <RelativeLayout 
       android:id="@+id/a" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:orientation="vertical" > 
      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/b" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:orientation="vertical" > 
      </RelativeLayout> 
     </LinearLayout> 
1

使用表佈局它自動調整它

<TableLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:padding="5dp" 
     android:shrinkColumns="1" 
     android:stretchColumns="1" > 

     <TableRow android:id="@+id/tableRow1" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Main Status    " 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

      <Button 
       android:id="@+id/retentionMainStatus" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="CLICK ME" /> 
</TableRow> 
</TableLayout> 
相關問題