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?
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.
Have you tried this one ?
android:footerDividersEnabled="true"
if not try this out
<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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With