首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ListView最后一项后的分隔符(分隔符)

ListView最后一项后的分隔符(分隔符)
EN

Stack Overflow用户
提问于 2013-01-07 23:48:11
回答 6查看 37.2K关注 0票数 53

当我创建一个只有一个ListView的简单布局时,在最后一个项目后面没有显示分隔符,这看起来有点丑陋。

代码语言:javascript
复制
<?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="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true" />
</RelativeLayout>

但是,我发现如果我在listview下面添加另一个视图并为listview设置android:layout_above属性,那么在最后一项之后会显示一个分隔符

代码语言:javascript
复制
<?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="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bottom"
        android:layout_alignParentTop="true" />

    <TextView
        android:id="@+id/bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@android:color/holo_blue_dark"
        android:text="Bottom" />
</RelativeLayout>

为什么列表视图的行为是这样的?在只包含列表视图的布局中,如何在最后一项后添加分隔符?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2014-01-09 01:13:42

答案很简单:您应该在ListView中将android:layout_height="wrap_content"更改为android:layout_height="match_parent"

您可能会猜到为什么会发生这种情况。

票数 101
EN

Stack Overflow用户

发布于 2013-01-08 00:06:42

你试过这个吗?

代码语言:javascript
复制
android:footerDividersEnabled="true"

如果没有,请尝试以下操作

代码语言:javascript
复制
<View
android:background="#00ff00"
android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/YOUR_LIST_ID" />
票数 15
EN

Stack Overflow用户

发布于 2015-05-14 09:01:28

将空白视图添加到顶部(和/或底部)以在顶部(或底部)创建分隔线

代码语言:javascript
复制
myList.addHeaderView(new View(context));
myList.addFooterView(new View(context));
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14199274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档