Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display textview above a button without hardcoding the height in xml

Tags:

android

I am displaying a textview(I intend this to fill the entire screen excluding the button below it) and a button(small one at the bottom) in an activity. I want textview to be placed aove the button. I don't want to hardcode any height/width.

Hence For button I have kept height ad width as word_wrap For textview I have kept width as fill parent.

What I want to know is that, is there anyway by whcih I can specify textview height to be screenheight-button height. I want to this in xml file but not dnamically inside my code.

like image 796
user1938357 Avatar asked Jan 05 '13 12:01

user1938357


1 Answers

To achieve this you have to create something like this :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/button1"
        android:text="TextView" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Button" />

</RelativeLayout>

and you have a textview which will stay above your button and will fit the entire screen.

like image 89
hardartcore Avatar answered Oct 22 '22 09:10

hardartcore