2012-02-08 53 views
0

我在XML文件中定義了一個表格行。 它包含3'的LinearLayout」一上的其他頂級: 我想獲得這個樣子:以最大高度平均間距LinearLayouts

|-------------------------------| 
|        | 
|    a    | 
|        | 
|        | 
|-------------------------------| 
|        | 
|    b    | 
|-------------------------------| 
|        | 
|    c    | 
|-------------------------------| 

‘問題’是,LinearLayout‘A’可能會擴大,並在同時,「不同的高度b「和」c「總是處於相同的高度。

我會找到LinearLayout的最大高度的和強制執行這個高度是所有其他LinearLayout的高度的太多,所以我會得到這個樣子的每一行:

|-------------------------------| 
|        | 
|    a    | 
|        | 
|        | 
|-------------------------------| 
|        | 
|    b    | 
|        | 
|        | 
|-------------------------------| 
|        | 
|    c    | 
|        | 
|        | 
|-------------------------------| 

我嘗試使用android:layout_weight沒有成功...

任何想法?

+0

layout_weight是正確的道路要走,你怎麼嘗試使用它? – Jave 2012-02-08 09:21:16

+0

要使'android:layout_weight'正常工作,必須將每個'LinearLayout'的'android:layout_height'設置爲'0dp'。 – Squonk 2012-02-08 09:23:01

+0

我嘗試了所有與'android:layout_height'(0dp,wrap_content,...)沒有任何成功的變化 - 我總是得到相同的不想要的外觀。與此同時,我給頂級父母固定'dp'大小,現在它顯然工作,但這不是這樣做的最佳方式... – ofirbt 2012-02-08 09:27:25

回答

0

我試圖在一個例子中實現這個。 這裏是我做過什麼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#ff0000" 
     > 
      <TextView 
      android:layout_width="30dip" 
      android:layout_height="wrap_content" 
      android:text="hjadsh haksj hasjk haksj hjkas hkjas hjkas hkjas " 
      android:textColor="#000000" 
      /> 

    </LinearLayout> 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#00ff00" 
     ></LinearLayout> 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:background="#0000ff" 
     ></LinearLayout> 

</LinearLayout> 

我用TextView的第一佈局中,以顯示它可以作爲你所需要的。 您還可以通過設置layout_height來固定佈局b & c的高度,使其具有固定高度並改變佈局a:wrap_content

您現在可以根據自己的需要對其進行自定義。

0

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 
    </LinearLayout> 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:background="#00ffff" 
    ></LinearLayout> 

    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" > 
    ></LinearLayout> 
</LinearLayout>