George
George

Reputation: 1327

LinearLayout problem

I have this code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutAnim"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

       <LinearLayout 
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/leftCornerImage"
          android:orientation="vertical"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent">

            <ImageButton
              android:id="@+id/btnNight"
              android:layout_width="62px"
              android:layout_height="62px"  />

            <ImageButton
              android:id="@+id/btnAlarm"
              android:layout_width="62px"
              android:layout_height="62px"  />

            <ImageButton
              android:id="@+id/btnThermo"
              android:layout_width="62px"
              android:layout_height="62px"
              android:layout_gravity="bottom"  />

             <ImageButton
              android:id="@+id/btnDigital"
              android:layout_width="62px"
              android:layout_height="62px"
              android:layout_gravity="bottom"  />
     </LinearLayout>

    <LinearLayout .....
    </LinearLayout>

</LinearLayout>

Can somebody helps me. Why android:layout_gravity="bottom" doesn't work? If you have the better solution, please help me.

Upvotes: 0

Views: 282

Answers (3)

Nathan Schwermann
Nathan Schwermann

Reputation: 31493

The parent controls the gravity so android:gravity="bottom" should be in the containing linear layout instead. Note this will affect all of the views. If you want only the last view to hug the bottom, either use a RelativeLayout or place a plain view in between the two images and set its layout_weight to 1.

Hope this helps!

Upvotes: 0

woodshy
woodshy

Reputation: 4111

android:layout_gravity="bottom" here goes for text inside button.
If you want buttons anchered to the bottom, you should provide android:gravity="bottom"> to first inner LinearLayout.

Upvotes: 0

Ted Hopp
Ted Hopp

Reputation: 234795

A vertical LinearLayout will only honor horizontal gravity; a horizontal LinearLayout will only honor vertical gravity. Use RelativeLayout, or else use android:layout_weight to distribute extra vertical space where you want it.

Upvotes: 2

Related Questions