101

I have a fixed height ListView. It has divider between list items, but it also displays dividers after the last list item.

Is there a way to not display a divider after the last item in ListView?

seb
  • 4,279
  • 2
  • 25
  • 36
mkso
  • 3,178
  • 4
  • 27
  • 35

5 Answers5

184

Just add android:footerDividersEnabled="false" to your ListView description

Alex.Semeniuk
  • 1,872
  • 1
  • 12
  • 2
  • 29
    This seems to no longer work starting with 4.4.2. I can run literally the same app across my many test devices (ranging from 2.3.7 all the way up until 4.4.2) and KitKat is the only one where this seems to have no effect... Any ideas? I'm not adding a footer or header to my ListView and I've reproduced this on two devices (Nexus 5 and HTC One M8). – Charles Madere Apr 11 '14 at 17:53
  • 11
    @ScootrNova I'm using 4.4.4, and when I set the listview's `layoutHeight="wrap_content"`, the bottom divider disappears. – Erhannis Jul 10 '14 at 22:33
  • 1
    Use background = @android:color/transparent, solved it for me – stef Feb 23 '18 at 12:11
  • tried this solution on android 5.1 and 7.0 and it perfectly works! Thanks man. – tomalf2 Apr 28 '18 at 14:58
90

As @ScootrNova said, this seems to be behaving differently (a.k.a buggy) in android 4.4.x (I don't know exactly when the problem is introduced)

This is related to the specific case of using using padding + clipToPadding="false" - in 4.4.x the footer is drawn outside of the view but clips to padding reveals it.

The solution I used was to set the footer over-scroll (android:overScrollFooter) to transparent which somehow works...

My final solution (note that android:footerDividersEnabled is kept for back-compatibility):

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/activity_horizontal_margin"
    android:divider="@color/divider"
    android:dividerHeight="1px"
    android:clipToPadding="false"
    android:scrollbarStyle="outsideInset"
    android:overScrollFooter="@android:color/transparent"
    android:footerDividersEnabled="false"
    />

tested on a HTC One X running 4.1.1, a Nexus 5 running 4.4.4 and a Samsung Galaxy S5 running 4.4.2 (thanks to @Dallas187). Seems to be working Lollipop too. (thanks to commenters!)

Sam
  • 3,453
  • 1
  • 33
  • 57
19

If you want to do this by code it's:

listView.setFooterDividersEnabled(false);

and if you're using a ListFragment you can get the listview by:

listFragment.getListView().setFooterDividersEnabled(false);

Only commented because this comes up as #1 in google

Ahmad
  • 69,608
  • 17
  • 111
  • 137
tmho
  • 1,508
  • 14
  • 13
  • 2
    Thank you for the code - I get sad when there are only XML based solutions! I am porting an app from iOS to Android, and so far I think doing this all in code was much faster than if I had of tried converting it all into XML based layout (as I defined all the iOS UI in code in the first place). I suppose one day I'll have to get my head around all this XML stuff, but not today :) – Herr Grumps Oct 29 '12 at 11:18
  • Not working for me on Pixel API 25, only Annada's suggestion seems to do it. – Tbadams May 01 '18 at 18:08
15

It seems below line does not work on lollypop device.

listView.setFooterDividersEnabled(false);

So need to use this below code to remove divider after last item in the list.

listView.setOverscrollFooter(new ColorDrawable(Color.TRANSPARENT));
Annada
  • 1,075
  • 1
  • 18
  • 21
0

Use background = @android:color/transparent. Works perfectly. You can still use the background of your row layout

stef
  • 161
  • 1
  • 10