user1015311
user1015311

Reputation: 403

How to put the button really at the bottom

I'm trying to put some buttons at the bottom of my linear layout. The button just appears after the text,I want it to appear after the text but at the bottom. Here's the code:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="30dip"
android:background="@color/background">

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_gravity="center" android:layout_height="match_parent">

<TextView
android:id="@+id/test"
android:text="This is a test"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="16.5sp" />


 <Button
 android:layout_height="wrap_content"
 android:layout_width="wrap_content"
 android:layout_gravity="bottom"
 android:text="continue"

 android:id="@+id/continuebutton"
  />

 </LinearLayout>

 </LinearLayout>

Upvotes: 1

Views: 792

Answers (1)

Dimitris Makris
Dimitris Makris

Reputation: 5183

Using LinearLayout, the only you can do is to have this:

<TextView
    android:id="@+id/test"
    android:layout_width="wrap_content"
    android:layout_height="0dp" <---
    android:layout_gravity="center"
    android:layout_marginBottom="25dip"
    android:layout_weight="1" <---
    android:text="This is a test"
    android:textSize="16.5sp" />

<Button
    android:id="@+id/continuebutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" <---
    android:layout_gravity="bottom"
    android:layout_weight="0" <---
    android:text="continue" />

Please check the rows with: <---

Of course the best way probably is to use a RelativeLayout and have the Button alignParentBottom like this:

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical" >

<TextView
    android:id="@+id/test"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="25dip"
    android:text="This is a test"
    android:textSize="16.5sp" />

<Button
    android:id="@+id/continuebutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="continue" android:layout_alignParentBottom="true"/>
</RelativeLayout>

Hope this helps!!

Upvotes: 5

Related Questions