2012-10-15 84 views
3

我有以下困境。兩個元素,一個在另一個之上。底部有高度爲wrap_content。我希望頂層元素填充剩餘空間,而不使兩個元素重疊(如果我使用FrameLayout,則會發生這種情況)。所有元素的寬度爲match_parent垂直佈局,2個元素,使頂部填充剩餘空間(底部有一個wrap_content)

這裏的樣機(某些屬性截斷清晰度):

<LinearLayout android:layout_height="match_parent"> 

    <CustomView android:layout_height="???????" /> 

    <TextView android:layout_height="wrap_content"> 

</LinearLayout> 

回答

9
<CustomView 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    .../> 
+0

「中的FrameLayout佈局無效PARAM:layout_weight」。請注意,父'LinearLayout'沒有定義'weightSum',這可能是原因。任何想法如何繼續? –

+1

不,你不需要'weightSum'。這應該只是一個問題,如果直接父母是一個「FrameLayout」,而不是像上面顯示的那樣的「LinearLayout」。如果你在'FrameLayout'中需要它,將加權視圖包裝在'LinearLayout'中。 – Geobits

+0

你是對的。出於某種原因,我使用了FrameLayout。 –

相關問題