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>
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>
Why does the listview behave like this? How can I get a separator after the last item in a layout that contains only a listview?
ListView
in the layout I think you could always(and pretty easy) implement an adapter that adds an extra empty row to force showing the target divider. – KinderisEnabled(position)
method of the adapter to returnfalse
for that empty last position. – Kinder