分离器(分)的ListView的最后一个项目后,分离器、项目、ListView

2023-09-04 23:52:38 作者:苦苦撑到现在

当我创建一个简单的布局,它只是一个ListView,有的最后一个项目,它看起来有点后显示没有分隔难看。

When I create a simple layout with only a ListView in it, there is no separator displayed after the last item, which looks a bit ugly.

<?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和设置安卓显示的最后一个项目之后:layout_above 属性的列表视图。

However, I found out that a separator is displayed after the last item if I add another view bellow the listview and set the android:layout_above attribute for the 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_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布局的最后一个项目后隔板?

推荐答案

答案很简单:你应该改变安卓layout_height =WRAP_CONTENT机器人:layout_height =match_parent的ListView

The answer is very simple: you should change android:layout_height="wrap_content" to android:layout_height="match_parent" in your ListView.

您可能已经猜到为什么会这样。

You can probably guess why this happens.