429

I'm using two ListViews like this:

<ListView
   android:id="@+id/ListView"
   android:text="@string/Website"
   android:layout_height="30px"
   android:layout_width="150px"
   android:scrollbars="none"
   android:transcriptMode="normal"/>
<ListView
   android:id="@+id/ListView1"
   android:text="@string/Website"
   android:layout_height="30px"
   android:layout_width="150px"
   android:scrollbars="none"
   android:transcriptMode="normal"/>

There is one blank line between the two ListViews. How do I remove it?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
deepthi
  • 8,477
  • 12
  • 35
  • 36
  • 3
    Do you have two separate ListViews showing different lists or do you mean you have a line between items in your ListView? – David Webb Dec 16 '09 at 13:03
  • Is it "blank" or "black" line? Since the question got edited by someone other than the OP. There is a difference between those – miva2 Oct 14 '15 at 08:26
  • 1
    @deepthi, would you consider marking one of the answers as accepted? – Antek Jan 23 '19 at 11:47

14 Answers14

971

To remove the separator between items in the same ListView, here is the solution:

getListView().setDivider(null);
getListView().setDividerHeight(0);

developer.android.com # ListView

Or, if you want to do it in XML:

android:divider="@null"
android:dividerHeight="0dp"
Lyudmil
  • 1,163
  • 2
  • 13
  • 21
dasilvj
  • 10,356
  • 2
  • 17
  • 16
97
  1. If you want to remove a divider line, use this code:

    android:divider="@null"
    
  2. If you want to add a space instead of a divider line:

    android:divider="@android:color/transparent"
    android:dividerHeight="5dp"
    

So, you can use any drawable or color in the divider attribute.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Amintabar
  • 2,198
  • 1
  • 29
  • 29
66

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 two different ways to do this in a ListView:

1. Set divider to null:

1.1. Programmatically

yourListView.setDivider(null);

1.2. XML

This goes inside your ListView element.

android:divider="@null"

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"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sotti
  • 14,089
  • 2
  • 50
  • 43
  • 1
    In certain situations there seems to be an issue with simply setting the divider color to transparent. My ListView elements each had a solid-colored, semi-transparent background. When I was using the second method of hiding the divider, a "divider" still seemed to appear. When I switched to the first method, the "divider" disappeared. – themarshal Nov 30 '15 at 21:40
32

Set divider to null:

JAVA

  listview_id.setDivider(null);

XML

<ListView 
  android:id="@+id/listview"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:divider="@null"
  />
Saneesh
  • 1,796
  • 16
  • 23
27

In XML:

android:divider="@null"

Or in Java:

listView.setDivider(null);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Khalid Taha
  • 3,183
  • 5
  • 27
  • 43
18
   <ListView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/list"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:divider="@null"
  android:dividerHeight="0dp"/>
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Donald Duck Jan 25 '17 at 13:54
12

You can put below property in listview tag

android:divider="@null"

(or) programmatically listview.Divider(null); here listview is ListView reference.

JoeBilly
  • 3,057
  • 29
  • 35
sandeepmaaram
  • 4,191
  • 2
  • 37
  • 42
10

Or in XML:

android:divider="@drawable/list_item_divider"
android:dividerHeight="1dp"

You can use a color for the drawable (e.g. #ff112233), but be aware, that pre-cupcake releases have a bug in which the color cannot be set. Instead a 9-patch or a image must be used..

Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
Mads Kristiansen
  • 2,604
  • 1
  • 17
  • 15
  • Or you can even use the standard Android drawable for the divider: `@android:drawable/divider_horizontal_...` – racs Jun 17 '16 at 01:44
9

You can try the following. It worked for me...

android:divider="@android:color/transparent"
android:dividerHeight="0dp" 
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zia
  • 2,365
  • 2
  • 17
  • 14
7

I find it easier to implement it in the XML file as it can be harder to trace the line of code in a class with hundreds of lines. For the XML you can use "null":

android:divider="@null"
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fred
  • 332
  • 4
  • 5
5

For ListFragment use

getListView().setDivider(null)

after the list has been obtained.

Meanman
  • 1,474
  • 20
  • 17
3

If you want to remove lines from

⛔ Problem

Having lines between items from <ListView>

✅ Solution

add an attribute android:drivider="@null"

enter image description here

0

If this android:divider="@null" doesn't work, maybe changing your ListViews for Recycler Views? 

Richard Nikolas
  • 505
  • 4
  • 11
-1

String txt = ( (TextView) view).getText().toString();
adapter.remove(txt);
  

enter image description here