更改Android中ListView下方的空白颜色

时间:2014-03-03 22:37:14

标签: android xml listview android-listview

最后一行下方仍有一小块白色区域。为什么允许使用以下代码进行此操作?

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/lightGray">

    <ListView
        android:id="@+id/home_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white" >
    </ListView>

</LinearLayout>

更新:感谢大家的建议。问题是因为在我的适配器的getView中膨胀自定义行时我正在做的一些奇怪的事情。我希望ListView的行大小不同。很明显,listview是根据计算第一行膨胀的高度乘以行数得到它的总高度。这导致了一个问题,因为我的所有行都不是相同的大小。我最终根据加起来的每行的高度动态地改变了列表视图的高度。

3 个答案:

答案 0 :(得分:0)

它可能是分隔符 - 尝试将其设置为透明(或您选择的颜色)您也可以更改高度:

    <ListView
        android:id="@+id/home_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp"
        android:padding="10dp" />

答案 1 :(得分:0)

尝试将layout_widthlayout_height值更改为fill_parent

<ListView
        android:id="@+id/home_listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white" >
    </ListView>

答案 2 :(得分:0)

我最终得到的解决方案是让ListView背景颜色与LinearLayout背景颜色相同,但是使ListView的每一行都是我真正想要ListView的颜色。这样,如果ListView底部有额外的空间,因为高度计算不正确,它看起来就像是背景的一部分。使用此解决方案,我也不必担心对ListView进行动态高度计算。