列表视图占用的空间超出了需要

时间:2014-09-17 19:01:29

标签: android

这是我的自定义对话框,由以下

组成

列表视图,按钮,最后是列表为空时使用的文本视图。

我的问题是当只有1个项目存在时,listview似乎占用的空间比它需要的空间多。

下图显示了这一点。

enter image description here

我的XML代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/lvRaffles"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bCloseDialog"
        android:layout_alignParentTop="true" >

    </ListView>

    <Button
        android:id="@+id/bCloseDialog"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@drawable/alert_dialog_button_style"
        android:text="Close" />

    <TextView
        android:id="@+id/tvRaffleEmpty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="No Raffle Code Found With That Search"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:visibility="gone" />

</RelativeLayout>

我尝试了以下内容。 在wrap_content上列出视图高度,0dp没有帮助。

1 个答案:

答案 0 :(得分:0)

我知道你用LinearLayout解决了这个问题,但回答你的问题,看起来好像你的listview占用太多空间的原因是因为你使用了layout_alignParentBottom =&#34; true&#34;如果您希望按钮显示在列表视图下方,则需要使用layout_below =&#34; @ id / lvRaffles&#34;您还有两个与parentTop对齐的元素,这可能导致元素重叠。

相关问题