Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align Button to Bottom using LinearLayout

Trying to align button at Bottom using LinearLayout, but getting just below TextView.

To set button at bottom, I am using android:layout_gravity="bottom" but still not done

LinearLayout xml

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="0dp"
        android:layout_height="match_parent"            
        android:orientation="vertical" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"/>

        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_gravity="bottom"
            android:layout_height="wrap_content">

            <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Bottom" />

        </LinearLayout>

 </LinearLayout>
like image 462
Oreo Avatar asked Mar 25 '26 17:03

Oreo


2 Answers

Change second linear layout to

<LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal" >

This will put the button at the bottom and this layout will take the rest of the space

like image 123
Ankit Aggarwal Avatar answered Mar 28 '26 16:03

Ankit Aggarwal


Yoy have to use like this....

<RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center">
        <Button
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Bottom" />
    </RelativeLayout>
like image 30
Saurabh Vardani Avatar answered Mar 28 '26 18:03

Saurabh Vardani