当我创建一个只有一个ListView的简单布局时,在最后一个项目后面没有显示分隔符,这看起来有点丑陋。
<?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
属性,那么在最后一项之后会显示一个分隔符。
<?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>
为什么列表视图的行为是这样的?在只包含列表视图的布局中,如何在最后一项后添加分隔符?
发布于 2014-01-09 01:13:42
答案很简单:您应该在ListView
中将android:layout_height="wrap_content"
更改为android:layout_height="match_parent"
。
您可能会猜到为什么会发生这种情况。
发布于 2013-01-08 00:06:42
你试过这个吗?
android:footerDividersEnabled="true"
如果没有,请尝试以下操作
<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" />
发布于 2015-05-14 09:01:28
将空白视图添加到顶部(和/或底部)以在顶部(或底部)创建分隔线
myList.addHeaderView(new View(context));
myList.addFooterView(new View(context));
https://stackoverflow.com/questions/14199274
复制相似问题