Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

android - Listview divider margin

I'm trying to set a margin to a listview divider.
The divider is a dashed line:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line" >
    <stroke
        android:dashGap="1dp"
        android:dashWidth="1.5dp"
        android:width="1dp"
        android:color="#FF404040" />

    <size android:height="3dp" />

</shape>

and a listview where i set the divider

<ListView
    android:id="@+id/lv_news_feed_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:divider="@drawable/ch_dashed_line_divider"
    />

but I want a divider margin left and right. I also tried to set a padding to the shape, but the listview is ignoring the padding.

    <padding
        android:bottom="15dp"
        android:left="15dp"
        android:right="15dp"
        android:top="15dp" />

Is there any possibility to set a margin to the listview divider - except in the getView() of the Adapter?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Inset is the way to go

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

    <shape
        android:shape="line" >
        <stroke
            android:dashGap="1dp"
            android:dashWidth="1.5dp"
            android:width="1dp"
            android:color="#FF404040" />

            <size android:height="3dp" />

    </shape>

</inset>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...