2011-02-02 111 views
2

大家好 我需要的是按钮必须显示在底部,所以我的代码按钮线性布局不显示

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="12dip"> 

    <ListView 
     android:id="@+id/list_multiselectable" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical"> 
    </ListView> 
<LinearLayout android:orientation="horizontal"   

    android:background="@android:drawable/bottom_bar" 
    android:paddingLeft="4.0dip" android:paddingTop="5.0dip" 
    android:paddingRight="4.0dip" android:paddingBottom="1.0dip" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"> 

    my buttons code here 
</LinearLayout> 
    </LinearLayout> 

但是,当在列表中的项目较少(直到列表视图的滚动条不启用),按钮是可见的,但是当列表中的项目更多时,虽然我将列表项目滚动到最后一行,但最后没有显示按钮,但按钮不可见。我该如何解决它。

谢谢!

回答

4

LinearLayout是给ListView它需要的所有空间,因为它依次考虑它的孩子,不考虑那些跟随。

我的建议是使用RelativeLayout。

<RelativeLayout ...> 
    <ListView ... 
      android:id="@+id/list" 
      android:layout_alignParentTop="true"/> 
    <LinearLayout ... 
      android:layout_below="@id/list" 
      android:layout_alignParentBottom="true"> 
    ...buttons... 
    </LinearLayout> 
</RelativeLayout> 
+0

请问您可以添加更多的细节到列表视图和linearlayout的属性。 – 2011-02-02 12:03:04

1

您可以设置列表视图的最小高度 320 * 480 listview height = 430 按钮的布局高度= 50

+0

同样的问题正在发生。 – 2011-02-02 11:10:21

2

我不确定。但是你可以尝试设置你的listview的权重。

<ListView 
     android:id="@+id/list_multiselectable" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:layout_gravity="center_vertical"> 
    </ListView>