列表视图与下面的按钮无法正常工作

问题描述:

我在对话框中有一个ListView,我需要在列表后显示一个按钮。列表视图与下面的按钮无法正常工作

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content"> 
<TextView android:id="@+id/tvwGameOver" android:layout_weight="1" android:gravity="center" 
      android:textSize="25sp" android:visibility="gone" 
      android:layout_width="fill_parent" android:layout_height="wrap_content"/> 
<LinearLayout 
    android:id="@+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:orientation="horizontal" android:footerDividersEnabled="true" 
    android:headerDividersEnabled="true" android:layout_below="@id/tvwGameOver"> 
    <TextView 
    android:id="@+id/tvwGameNumberHeader" android:layout_weight="1" android:gravity="right" 
    android:text="@string/scores_GameNumber" android:textSize="12sp" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_marginRight="13sp"/> 
    <TextView 
    android:id="@+id/tvwPlayer0Name" android:layout_weight="1" android:gravity="right" 
    android:textSize="12sp" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_marginRight="13sp"/> 
    <TextView 
    android:id="@+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right" 
    android:textSize="12sp" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_marginRight="13sp"/> 
    <TextView  
    android:id="@+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right" 
    android:textSize="12sp" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_marginRight="13sp"/> 
    <TextView  
    android:id="@+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right" 
    android:textSize="12sp" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:layout_marginRight="13sp"/> 
</LinearLayout> 


    <ListView 
    android:id="@+id/lvwScores" android:layout_below="@id/lloPlayerNames" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" 
    android:divider="#FFFFFF" android:dividerHeight="1dip" 
    android:layout_weight="1" 
    android:footerDividersEnabled="true" android:headerDividersEnabled ="true"/> 

<Button android:id="@+id/btnOK" 
    android:layout_height="wrap_content" android:layout_width="120dip" 
    android:layout_weight="1" 
    android:text="OK" android:layout_centerHorizontal="true" 
android:layout_alignParentBottom="true" 

    /> 
</RelativeLayout> 

问题是,当列表变得太大时,它只是通过按钮,按钮位于列表顶部。

我试着将android:layout_below =“@ id/lvwScores”添加到按钮中,但是当列表为空时,我得到一个从屏幕底部运行到列表底部的按钮。

如果我删除了android:layout_alignParentBottom =“true”,那么对话框会变小。

在一天结束时,即使部分屏幕仍然是空的(这是一个屏幕分数),我希望能够填充大部分屏幕,并且按钮位于底部。

任何想法?

这是什么样子的空当: enter image description here

这是伟大的,除了当列表积聚并达到底部降下来,不是在按钮停止。

+0

RelativeLayout有什么意义?要始终在底部有按钮?为什么不使用LinearLayout并给ListView权重1? – dmon 2011-06-14 20:08:11

你可能给列表视图或列表视图的容器在底部的边缘是按钮的高度?就像测试一样,给按钮30下的高度,并让listview或listview的容器的下边距为30下,以查看它是否仍然在按钮后面运行。

+0

我会试一试。需要几分钟时间来完成。 – theblitz 2011-06-14 20:19:37

+0

完美!非常感谢! – theblitz 2011-06-14 20:28:44

+0

很高兴为您服务 – 2011-06-14 20:55:22

按钮应该具有 android:layout_below="@id/lvwScores"

alignParentBottom不是不FILL_PARENT RelativeLayouts最好的办法。

+0

问题是我希望列表填充对话框,即使它是空的。请参阅编辑。 – theblitz 2011-06-14 20:16:51