2016-09-25 70 views
0

我目前的Android佈局設計看起來是這樣的(僞)如何在android佈局的屏幕底部選擇覆蓋層的wrap_content高度?

<RelativeLayout width&height=match_parent> 

    <RelativeLayout width&height=match_parent> 
     <!-- App content here --> 
    </RelativeLayout> 

    <RelativeLayout width=match_parent height=wrap_content> 
     <!-- These views should overlay the bottom of the screen --> 
     <Textview /> 
     <Button /> 
    </RelativeLayout> 

</RelativeLayout> 

的問題是,覆蓋部分的高度應以顯示所有文本所需的高度。該按鈕應該複製TextView的高度。

我把這樣的:

button height: match_parent 
textview height: wrap_content 

但:按鈕的match_parent似乎走的空間全屏,因爲它的父包的內容(Like this!)。

如果我把TextView和Button的高度作爲wrap_content:我有另一個問題。該按鈕的高度小於TextView的高度。

有沒有人有任何想法我可以解決這個問題?

回答

1

該按鈕應複製TextView的高度。

您可以用的TextView的頂部對齊按鈕,使用RelativeLayout的底部屬性layout_alignToplayout_alignBottom

<RelativeLayout width=match_parent height=wrap_content> 
     <!-- These views should overlay the bottom of the screen --> 

     <Textview 
      android:id="@+id/textview"/> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignTop="@+id/textview" 
      android:layout_alignBottom="@+id/textview"/> 
    </RelativeLayout> 
+0

這是解決方案!它工作得很好,非常感謝!我沒有意識到alignTop&alignBottom屬性。只需指出:Button的高度應該是wrap_content,並且TextView的高度應該是wrap_content與此方法。 –

相關問題