Kevin Van Ryckegem Kevin Van Ryckegem - 2 months ago 19
Android Question

How to choose wrap_content height of overlay on bottom of screen in android layout?

My current Android lay-out looks like this (pseudocode)

<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>


The problem is that the height of the overlay section should be the height required in order to display all the text. The button should copy the TextView's height.

I put like this:

button height: match_parent
textview height: wrap_content


but: the match_parent of the button seems to be taking the full screen of space, because the parent of it is wrapping the content (Like this!).

If I put the TextView and Button's heights as wrap_content: I have another problem. The button's height is smaller than the TextView's height.

Does anybody have any idea how I could fix this?

Answer

The button should copy the TextView's height.

You can align the Button with the TextView's Top and Bottom using the RelativeLayout attributes layout_alignTop and layout_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>
Comments