2016-11-14 74 views
1

我想要一個嵌套的片段,它應該佔用剩下的空間。問題是它甚至沒有顯示,因爲高度是1像素。例如,如果我將高度設置爲300 dp,則一切看起來都不錯。這是我的代碼。也許佈局無法計算究竟是其他兩個佈局:填充其餘空間的嵌套片段

  <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical"> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/white_with_divider_bg" 
       android:id="@+id/firstL"> 

      </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/secondL" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp"> 

      </RelativeLayout> 

      <FrameLayout 
       android:id="@+id/child_fragment" 
       android:layout_height="0dip" 
       android:layout_width="match_parent" 
       android:layout_weight="1"/> 

     </LinearLayout> 

的高度,它應該是這樣的:

enter image description here

+0

您可以使用單個RelativeLayout,而不是使用所有嵌套的佈局(對性能和糟糕的設計不好)。甚至在這種情況下,甚至可以使用一個LinearLayout(它也更快)。 –

+0

佈局複雜,每個子佈局內都有很多視圖,因此我只展示了主邏輯。 – charbinary

+0

對於你所展示的,一個LL就足夠了。如果它更復雜,則考慮使用單個RL。 –

回答

0

當權工作LiniearLayout的所有兒童都應有一個體重,但這不會幫助你。你應該有android:id =「@ + id/child_fragment」has height =「match_parent」並去掉重量。

這應該工作。

+0

我已經嘗試過了,它是一樣的。 – charbinary

+0

嗯。你可以嘗試的另一個解決方案是用一個RelativeLayout替換LiniearLayout,並使用上面和下面的屬性,你可以給孩子。 – miqueloi