2012-11-03 20 views
1

這裏是我的xml:的RelativeLayout:共享光幕高度

<RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       > 

      <LinearLayout android:layout_alignParentTop="true" 
          android:layout_height="wrap_content" 
          android:layout_width="fill_parent" 
          android:id="@+id/llRow1" /> 
      <LinearLayout android:layout_height="wrap_content" 
          android:layout_width="fill_parent" 
          android:layout_below="@+id/llRow1" 
          android:id="@+id/llRow2" /> 
      <LinearLayout android:layout_alignParentBottom="true" 
          android:layout_height="wrap_content" 
          android:layout_width="fill_parent" 
          android:id="@+id/llRow3" > 
</RelativeLayout> 

我想什麼都有: - 這3個「行」已共享屏幕高度 - 但有一個額外的:當我設置第3行(llRow3)對GONE的可見性,只有row1和row2必須共享屏幕高度。

怎麼可能做到這一點?

回答

2

對所有人設置相同的layout_weight。所以如果你將第三個可見性設置爲GONE,他們仍然會有這些權重。 編輯: 更改ParentLayout到的LinearLayout或者如果你需要RelitiveLayout,那麼你可以在其他的LinearLayout包裹這三個LinearLayout中,並設置權重,他們是這樣的:在RelativeLayout的

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <LinearLayout 
      android:id="@+id/llRow1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_weight="1" /> 

     <LinearLayout 
      android:id="@+id/llRow2" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/llRow1" 
      android:layout_weight="1" /> 

     <LinearLayout 
      android:id="@+id/llRow3" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_weight="1" > 
     </LinearLayout> 
    </LinearLayout> 

</RelativeLayout> 
+0

Layout_weight心不是可用... :( – Prexx

+0

啊,你沒有看到你使用了一個RelitiveLayout作爲你的ParentLayout,你可以將這三個LinearLayout包裝在另一個LinearLayout中嗎?這可以解決這個問題 – Ahmad

+0

好主意,我會試試這個:) – Prexx