Android
ListView
Line Removal
Android Development
UI Customization

How do I remove lines between ListViews on Android?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The lines between ListView items on Android are dividers. To remove them, you either set the divider drawable to @null or make the divider height zero. Both approaches tell the ListView not to draw item separators. The main thing to remember is that the lines are part of the ListView styling, not something built into the row layout itself.

Remove Dividers in XML

The most direct XML solution is:

xml
1<ListView
2    android:id="@+id/myListView"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent"
5    android:divider="@null"
6    android:dividerHeight="0dp" />

This removes the visible separator and also removes the extra vertical space that a divider height might reserve.

In many cases, setting either property is enough, but using both makes the intent explicit.

Remove Dividers Programmatically

If you need to adjust the behavior in code, you can do the same thing programmatically.

java
ListView listView = findViewById(R.id.myListView);
listView.setDivider(null);
listView.setDividerHeight(0);

This is useful when the divider behavior depends on runtime state or when the list is created dynamically.

Know What You Are Actually Removing

The standard ListView divider is not the same thing as spacing inside the row layout. If the rows still look separated after the divider is removed, the visual gap may come from:

  • padding in the row layout
  • margins in the row layout
  • a background drawable that creates separation
  • selector or card-style item design

That is why “remove the line” sometimes appears not to work. The divider may be gone while some other row styling still creates a boundary effect.

If You Want Custom Separation Instead of No Separation

Sometimes removing the built-in divider is only step one. You may want a cleaner custom look, such as card spacing or section blocks, rather than the default thin line.

In that case, remove the ListView divider first and then build spacing into the row layout intentionally.

That gives you more control than trying to style the default divider into every possible UI design.

RecyclerView Is Different

If you are working on newer Android UI code, note that RecyclerView does not use ListView dividers the same way. It typically uses ItemDecoration for separators and spacing.

So this solution is specifically about ListView. If the codebase uses RecyclerView, the equivalent fix lives elsewhere.

Check Theme and Style Overrides

Sometimes a style or theme applied to the ListView may set divider behavior indirectly. If your XML changes seem to do nothing, check whether a style resource is overriding:

  • divider drawable
  • divider height
  • background or selector styling

This is less common than simple XML fixes, but it does happen in older Android projects with layered themes.

Minimal Example in an Activity

A tiny working example looks like this:

java
1import android.app.Activity;
2import android.os.Bundle;
3import android.widget.ArrayAdapter;
4import android.widget.ListView;
5
6public class MainActivity extends Activity {
7    @Override
8    protected void onCreate(Bundle savedInstanceState) {
9        super.onCreate(savedInstanceState);
10
11        ListView listView = new ListView(this);
12        listView.setDivider(null);
13        listView.setDividerHeight(0);
14
15        String[] items = {"One", "Two", "Three"};
16        listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items));
17
18        setContentView(listView);
19    }
20}

This makes the behavior easy to verify independently of any larger layout file.

Common Pitfalls

The most common mistake is removing the ListView divider but leaving padding, margins, or custom row backgrounds that still create visible separation.

Another mistake is applying a ListView fix to a RecyclerView, which uses a different decoration model.

Developers also change only dividerHeight while a divider drawable is still present, or change only the drawable while other spacing still remains.

Summary

  • The lines between ListView rows are dividers, and you can remove them with android:divider="@null" and android:dividerHeight="0dp".
  • The same change can be made programmatically with setDivider(null) and setDividerHeight(0).
  • If row boundaries still appear, inspect padding, margins, and row backgrounds.
  • This solution applies to ListView, not RecyclerView.
  • Divider removal is a styling change on the list itself, not on the row adapter logic.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.