Remove the bottom divider of an android ListView
Asked Answered
S

5

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?

Sven answered 10/2, 2011 at 20:0 Comment(0)
M
184

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

Marshamarshal answered 25/2, 2011 at 14:35 Comment(4)
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).Cornice
@ScootrNova I'm using 4.4.4, and when I set the listview's layoutHeight="wrap_content", the bottom divider disappears.Rociorock
Use background = @android:color/transparent, solved it for meBari
tried this solution on android 5.1 and 7.0 and it perfectly works! Thanks man.Cohobate
C
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!)

Caffeine answered 24/6, 2014 at 18:56 Comment(3)
Just confirming this solution works on a Samsung Galaxy S5 running 4.4.2Runkel
Adding android:overScrollFooter did the trick for me. Working on a 5.0.2 and 5.1.Gauhati
indeed, and I believe you'll need android:footerDividersEnabled="false" for back compatCaffeine
B
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

Beckman answered 9/10, 2012 at 23:40 Comment(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 :)Ankylose
Not working for me on Pixel API 25, only Annada's suggestion seems to do it.Orlov
S
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));
Saury answered 28/7, 2016 at 20:59 Comment(2)
This should be the accepted answer. Simple solution, worked for me first shot.Exasperation
Bingo. Good stuff. Thanks for sharing!Amaral
B
0

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

Bari answered 23/2, 2018 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.