Remove ListView separator(in the xml layout file) [duplicate]
Asked Answered
N

6

146

How can I remove the rows separator in a ListView(if possible within the XML layout file where it's described)?

Navicert answered 16/8, 2011 at 16:25 Comment(0)
H
341

Set the dividerHeight to zero and divider to null like this in xml:

android:dividerHeight="0dp"
android:divider="@null"

Or in java:

getListView().setDividerHeight(0);
getListView().setDivider(null);
Hoarsen answered 6/5, 2012 at 8:36 Comment(5)
setting null is enough, height setting is redundantOffutt
Yeap, with divider to null is enough.Ipsus
I don't really understand where should I call getListView()?Tracietracing
@Neon - It's when you extend your Activity from ListActivity See here - developer.android.com/reference/android/app/ListActivity.htmlCarnify
If you use StickyListHeadersListView, you'll need both, setting to null won't be enoughObmutescence
U
79

Simply put:

android:divider="@null"
Unfleshly answered 6/5, 2012 at 7:48 Comment(0)
S
44

put below property in listview tag (in xml file)

android:divider="@null"
Scyphozoan answered 29/9, 2013 at 8:44 Comment(0)
F
19

You can set divider color as transparent color and divider height in 'ListView' properties to remove the divider like below:

android:divider="#00000000"  
android:dividerHeight="0dp" 
Fetor answered 16/8, 2011 at 16:33 Comment(1)
This was my first approach, but then I applied the above answer, put to divider to null.Ipsus
I
16

There are different ways to achieve this, but I'm not sure which one is the best (I don't even know is there is a best way). I know at least 2 different ways to do this in a ListView:

1. Set divider to null:

1.1. Programmatically

yourListView.setDivider(null);

1.2. XML

android:divider="@null" (this goes inside your ListView element)

2. Set divider to transparent and set its height to 0 to avoid adding space between listview elements:

2.1. Programmatically:

yourListView.setDivider(new ColorDrawable(android.R.color.transparent));
yourListView.setDividerHeight(0);

2.2. XML

android:divider="@android:color/transparent"
android:dividerHeight="0dp"
Ipsus answered 9/7, 2014 at 12:3 Comment(1)
Setting divider to null is obviously the best one, because it prevents any calculations being made by the system. The other is just a workaround.Miterwort
B
6

Only -1dp helps me to remove divider (not 0, 0.0, @null or the same in code)

Android Studio, SDK L, android 4.2

Bulbul answered 24/7, 2014 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.