A list ListView Android dividing line to add margins

We've added a list ListView dividing line is generally as follows:

<ListView
     android:id="@+id/taskList1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:divider="@color/list_divider"
     android:dividerHeight="1dp"/>

divider and dividerHeight with the use of the list there is a dividing line, but the question is, the dividing line is transparent, with the same wide list, if you want to add left and right margins how to do it? We need to use a resource xml picture.

List_divider_bg put yourself a drawable inside

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
       android:insetLeft="14dp"
       android:insetRight="14dp">

    <shape android:shape="rectangle">
        <solid android:color="@color/c_e6"/>
    </shape>

</inset>

Then you can reference in the ListView

<ListView
     android:id="@+id/taskList1"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:divider="@drawable/list_divider_bg"
     android:dividerHeight="1dp"/>
Published 59 original articles · won praise 88 · views 190 000 +

Guess you like

Origin blog.csdn.net/geofferysun/article/details/78072259