ab11
ab11

Reputation: 20090

Android: how to layout a fullscreen EditText, with a button below?

This seems simple, but I can't get it to work. I'd like to place a button at the bottom of the screen, and have an EditText occupy the rest of the available space. The below layout shows creates an EditText that occupies the full screen but the Button is not visible.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/textField"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </EditText>
    <Button
        android:id="@+id/button"
        android:text="text"
        android:layout_below="@id/textField"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    </Button>

</RelativeLayout>

Upvotes: 3

Views: 2723

Answers (2)

Bryan Herbst
Bryan Herbst

Reputation: 67189

Try the following inside your RelativeLayout:

<EditText
    android:id="@+id/textField"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/button" />

<Button
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

The problem with your original layout is that your EditText's height was set to match_parent and your button was set to be below that. match_parent caused the EditText to take up the full height of the screen, pushing the button below the bottom of the screen.

By telling the button to align itself to the bottom of the screen, then telling the EditText to lay itself out above that, you should be able to achieve what you are looking for.

Upvotes: 3

Lion
Lion

Reputation: 15

It is because of layout, you need to use the right layout. For example linear layout could help much more in this situation.

Upvotes: 0

Related Questions