techno
techno

Reputation: 6518

Align Buttons in Linear Layout to the Bottom of the Screen

I have the following layout

enter image description here

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

    <ImageView
        android:id="@+id/imageView1"
        android:layout_gravity="center"
        android:layout_width="200dip"
        android:layout_height="200dip"


     />
     <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_gravity="center"
        android:layout_height="wrap_content" />


    <LinearLayout
        android:layout_marginLeft="10dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tview_total"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:text="Total Files Processed:" />

        <TextView
            android:id="@+id/tview_success"
            android:layout_width="match_parent"
               android:gravity="right"
            android:layout_height="wrap_content"
            android:text="Successfully Processed:" />

        <TextView
            android:id="@+id/tview_error"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
               android:gravity="right"
            android:text="Error Processing:" />

    </LinearLayout>


  <LinearLayout
        android:id="@+id/llBottomContainer2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="bottom"
        android:gravity="bottom"
        android:padding="5dp" >       
         <Button
            android:id="@+id/proceed2"
            style="@style/btn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:background="@drawable/btn_sel"
            android:text="Proceed" />
    </LinearLayout>
</LinearLayout>

I want to align the Button on the bottom of the screen.I tried setting

android:layout_gravity="bottom"
        android:gravity="bottom" 

Does not work.What i'm i doing wrong?

Upvotes: 1

Views: 8099

Answers (3)

Balaje Venkat
Balaje Venkat

Reputation: 29

android:gravity="bottom"

Then make the gravity of layout or your button to the bottom

Upvotes: -2

V-rund Puro-hit
V-rund Puro-hit

Reputation: 5534

try this layout :

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

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

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="200dip"
            android:layout_height="200dip"
            android:layout_gravity="center" />

        <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tview_total"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:text="Total Files Processed:" />

            <TextView
                android:id="@+id/tview_success"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:text="Successfully Processed:" />

            <TextView
                android:id="@+id/tview_error"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:text="Error Processing:" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llBottomContainer2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="bottom"
        android:orientation="vertical"
        android:padding="5dp" >

        <Button
            android:id="@+id/proceed2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="Proceed" />
    </LinearLayout>

</RelativeLayout>

where android:layout_alignParentBottom="true" is key parameter.

Happy coding..

Upvotes: 1

Dharvik shah
Dharvik shah

Reputation: 1989

try this :

<LinearLayout
        android:id="@+id/llBottomContainer2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_gravity="bottom"
        android:gravity="bottom"
        android:padding="5dp" >

Upvotes: 4

Related Questions