views:

35

answers:

1

I have a Layout which contains a ListView some buttons below it.

What I want is for the buttons to be fixed to the bottom of the screen.

When the ListView has several items (more than what fits the screen) the code is working properly and the buttons appear in the bottom of the screen.

However, when the ListView is empty or does not require scrolling, the buttons are coming up the screen (they are not staying fixed in the bottom).

Here's the layout (some details omitted but I can add them if necessary):

<LinearLayout>
  <LinearLayout 
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="vertical" >
   <TextView />
   <ListView 
     android:width="fill_parent"
     android:height="wrap_parent"
     android:layout_weight="1" />
  </LinearLayout>
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|bottom" 
    android:orientation="horizontal"
    android:layout_weight="0" />
    <Button 
      android:layout_weight="1" />
    <Button 
      android:layout_weight="1" />
  </LinearLayout>
 </LinearLayout>

I expected setting the "gravity" of the second LinearLayout to "bottom" to make the buttons fixed to the bottom of the screen, but it's not working in the mentioned case.

Any ideas?

Thanks.

+1  A: 

You have the layout_height of your top LinearLayout set to wrap_content. This means that it will shrink as its contents shrink. Try setting it to fill_parent instead. Or, give it a layout_weight of 1.

Mayra