Search code examples
androidandroid-layoutuielement

Align buttons to the bottom of the layout


i want to align two buttons to the bottom of the screen as follows. i tried the xml given in this similar question but no luck.how to do it ?

like this -

enter image description here

this should be without the spacing in the bottom

enter image description here


Solution

  • This is the property you need to use:

    android:layout_alignParentBottom="true"
    

    Try using the following XML and customize your button appearance as you like:

    <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"
    android:background="#d1000000"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="PREV"
            android:layout_marginRight="-5dp"/>
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="NEXT"
            android:layout_marginLeft="-5dp"/>
    
    </LinearLayout>
    </RelativeLayout>