Android列表视图中未显示顶部和底部分隔符

Int*_*tor 18 android listview divider

我理解它的方式,为列表视图定义的分隔符也应该出现在列表的顶部和底部,即在第一个项目之上和最后一个项目之下.

出于某种原因,它们没有出现在我的列表视图中:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/background">

<ImageView
    android:id="@+id/home"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="3dp"
    android:paddingTop="3dp"
    android:paddingBottom="3dp"
    android:src="@drawable/homeicon"/>

<TextView
    android:id="@+id/titleBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Page Title" 
    android:layout_marginLeft="10dp" 
    android:paddingTop="3dp"
    android:textSize="18sp" 
    android:textStyle="bold" 
    android:typeface="serif" 
    android:textColor="#FFFFFF"
    android:layout_centerHorizontal="true"/>

<ImageView
    android:id="@+id/back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="8dp"
    android:paddingTop="8dp"
    android:src="@drawable/backicon" 
    android:layout_alignParentRight="true"/>


<ImageView
    android:id="@+id/separator1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/home"
    android:scaleType="fitXY"
    android:src="@drawable/separatorimg" />


<ListView
    android:id="@android:id/android:list" 
    android:layout_below="@+id/separator1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:cacheColorHint="#00000000"
    android:divider="@drawable/separatorimg">
</ListView>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

将android:footerDividersEnabled设置为true(这是围绕该问题的其他问题中给出的答案)不会改变任何东西.此外,我没有禁用项目,除非有某种默认的页脚将被禁用.

有任何想法吗?

编辑:当我滚过第一个/最后一个项目然后消失时,顶部和底部分隔符的分隔符似乎瞬间出现.它看起来好像接口将继续,只是稍后才意识到这是最后一项,然后禁用分隔符.

小智 29

我使用以下链接的帮助解决了这个问题:如果添加了footerview,分隔符将从listview中的最后一项消失

我做的是添加

  android:footerDividersEnabled="true" 
Run Code Online (Sandbox Code Playgroud)

属性为XML中的ListView.然后以编程方式,我添加了一个可以选择的空页脚视图

 listView.addFooterView(new View(context), null, true);
Run Code Online (Sandbox Code Playgroud)

我没有尝试标题,但我希望它的工作方式相同.

  • 对我来说,只有当页脚被标记为可选择时才会出现分隔符,即`addFooterView` 的最后一个参数是`true`。将其设置为 `false` 不会显示分隔符。 (2认同)

Arc*_*pgc 0

我认为您必须使用列表视图下方的视图来设置页脚。我遇到了同样的问题,这就是我可以获得的解决方案:

在列表中的最后一项之后显示分隔线