wawanopoulos
wawanopoulos

Reputation: 9794

Android : LinearLayout with 2 buttons at the bottom

I would like to set my linearlayout with 2 buttons side by side at the bottom of the view.

Today, with my code, the linearlayout stays at the top :(

Where is my mistake ?

<LinearLayout 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="#0099CC"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:gravity="bottom" >

         <LinearLayout
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginLeft="5dp"
             android:layout_marginRight="5dp"
             android:layout_weight="1"
             android:orientation="vertical" >

             <Button
                 android:id="@+id/startact_btn_connect"
                 style="?android:attr/borderlessButtonStyle"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="10dp"
                 android:background="@drawable/bg_blue_button_login"
                 android:text="Se connecter"
                 android:textColor="@color/blanc" />

             <View
                 android:layout_width="fill_parent"
                 android:layout_height="3dp"
                 android:layout_marginBottom="10dp"
                 android:background="@color/blue_pressed" />
         </LinearLayout>

         <LinearLayout
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginLeft="5dp"
             android:layout_marginRight="5dp"
             android:layout_weight="1"
             android:orientation="vertical" >

             <Button
                 android:id="@+id/startact_btn_view_annonces"
                 style="?android:attr/borderlessButtonStyle"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginTop="10dp"
                 android:background="@drawable/bg_blue_dark_button_login"
                 android:text="Voir les annonces"
                 android:textColor="@color/blanc" />

             <View
                 android:layout_width="fill_parent"
                 android:layout_height="3dp"
                 android:layout_marginBottom="10dp"
                 android:background="@color/blue_dark_pressed" />
         </LinearLayout>

     </LinearLayout>

</LinearLayout>

Upvotes: 2

Views: 1689

Answers (4)

Pararth
Pararth

Reputation: 8134

Change the following LinearLayout's height to match_parent:

 <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:gravity="bottom" >  

That said, you can also remove the nested linear layouts, and specify orientation:horizontal in the one mentioned above. Considering what you need the "view"(s) for, which are within the two nested layouts.

That would simplify your code and layout, something like:

<LinearLayout 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="#0099CC"
    android:orientation="vertical"
    android:paddingBottom="20dp"
    android:paddingTop="20dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/startact_btn_connect"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:text="Se connecter" />

        <Button
            android:id="@+id/startact_btn_view_annonces"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:background="@android:color/white"
            android:text="Voir les annonces" />
    </LinearLayout>

</LinearLayout>

Upvotes: 3

Patty P
Patty P

Reputation: 351

The key is that you have the orientation set to "vertical". This stacks the view on top of one another. To achieve the effect your looking for you'll want to set the orientation to "horizontal".

Upvotes: 0

schabluk
schabluk

Reputation: 708

Set android:layout_height="match_parent" to the first child of LinearLayout

<LinearLayout 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:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin" >

     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_gravity="top"
         android:gravity="bottom" >

         <!-- content -->

     </LinearLayout>

</LinearLayout>

Upvotes: 2

Akash Moradiya
Akash Moradiya

Reputation: 3322

try,

android:layout_gravity="bottom"

Upvotes: 0

Related Questions