2016-09-25 72 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与此方法。 –

相关问题