Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separator (divider) after last item of 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>

enter image description here

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>

enter image description here

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?

like image 526
Natix Avatar asked Jan 07 '13 15:01

Natix


2 Answers

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.

like image 73
olshevski Avatar answered Nov 11 '22 23:11

olshevski


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" />
like image 15
Gridtestmail Avatar answered Nov 11 '22 22:11

Gridtestmail