【发布时间】:2012-12-21 09:05:05
【问题描述】:
当我创建一个只有一个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>
但是,我发现如果我在列表视图下方添加另一个视图并为列表视图设置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>
为什么列表视图会这样?如何在仅包含列表视图的布局中的最后一项之后获得分隔符?
【问题讨论】:
-
如何在仅包含列表视图的布局中的最后一项之后获得分隔符? - 如果布局中只有
ListView,我认为您可以总是(而且很容易)实现一个适配器,它添加一个额外的空行来强制显示目标分隔符。 -
这很有趣,但最后一项不是可点击的吗?
-
如果您覆盖适配器的
isEnabled(position)方法以返回最后一个空位置的false,则不会。 -
将 ListView 高度 'from wrap_content' 更改为 'fill_parent'......它可能对我有用。
-
@ASP 比 Kzinch 早了近一个月就给出了正确答案!