How can I remove the rows separator in a ListView
(if possible within the XML layout file where it's described)?
Asked
Active
Viewed 7.2k times
146
6 Answers
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);

Priebe
- 4,942
- 3
- 24
- 38
-
36setting null is enough, height setting is redundant – X.Y. Nov 05 '13 at 21:10
-
Yeap, with divider to null is enough. – Sotti Jul 09 '14 at 11:03
-
I don't really understand where should I call getListView()? – Neon Warge Feb 26 '15 at 03:05
-
1@Neon - It's when you extend your Activity from ListActivity See here - http://developer.android.com/reference/android/app/ListActivity.html – Thahzan Mar 03 '15 at 06:30
-
1If you use StickyListHeadersListView, you'll need both, setting to null won't be enough – Quentin G. Feb 14 '17 at 17:48
44
put below property in listview tag (in xml file)
android:divider="@null"

sandeepmaaram
- 4,191
- 2
- 37
- 42
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"
-
1This was my first approach, but then I applied the above answer, put to divider to null. – Sotti Jul 09 '14 at 11:04
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"

Sotti
- 14,089
- 2
- 50
- 43
-
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. – xeruf Jan 19 '19 at 11:51
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

djdance
- 3,110
- 27
- 33