【问题标题】:Change color of blank space below ListView in Android在Android中更改ListView下方空白区域的颜色
【发布时间】:2014-03-03 22:37:13
【问题描述】:

最后一行下方仍有一小块区域是白色的。为什么允许使用以下代码发生这种情况?

<?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 的总高度是基于计算膨胀的第一行的高度乘以行数得出的。这引起了一个问题,因为我的所有行的大小都不相同。我最终根据添加的每一行的高度动态更改列表视图的高度。

【问题讨论】:

  • 请发个截图好吗?顺便说一句,我来自克林顿!小世界。
  • 可能是match_parent,我可能会用fill_parent,你试过了吗?
  • 天啊,fill_parent 已经被弃用了。这就是他使用match_parent 的原因。是的,截图不会是不必要的

标签: android xml listview android-listview


【解决方案1】:

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

    <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" />

【讨论】:

    【解决方案2】:

    尝试将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>
    

    【讨论】:

      【解决方案3】:

      我最终采用的解决方案是使 ListView 背景颜色与 LinearLayout 背景颜色相同,但使 ListView 的每一行成为我真正希望 ListView 成为的颜色。这样,如果由于高度计算不正确而导致 ListView 底部有多余的空间,它看起来就像是背景的一部分。同样使用此解决方案,我不必担心对 ListView 进行动态高度计算。

      【讨论】:

        猜你喜欢
        • 2011-09-24
        • 2019-07-04
        • 1970-01-01
        • 2015-12-15
        • 1970-01-01
        • 1970-01-01
        • 2019-03-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多