146

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

user
  • 86,916
  • 18
  • 197
  • 190
Caroline
  • 3,763
  • 5
  • 19
  • 25

6 Answers6

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
79

Simply put:

android:divider="@null"
avimak
  • 1,628
  • 11
  • 18
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" 
DKIT
  • 3,471
  • 2
  • 20
  • 24
romy_ngo
  • 1,061
  • 8
  • 15
  • 1
    This 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