How do I create a ListView with dashed / dotted line dividers in Android?

后端 未结 3 2138
攒了一身酷
攒了一身酷 2021-02-13 17:01

I managed to figure out how to create a custom shape (with a dashed stroke) by creating a file called dash.xml inside of the /app/res/drawable/ folder:

相关标签:
3条回答
  • 2021-02-13 17:14
    1. Define layerType for show the dotted line divider don't forget to give divider height.

    <ListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000" android:divider="@drawable/dash" android:dividerHeight="1dp" android:layerType="software"/>

    0 讨论(0)
  • 2021-02-13 17:15

    You also need android:dividerHeight. Shapes are variable size, and right now you have a zero-height divider.

    0 讨论(0)
  • 2021-02-13 17:29

    Here is mine and it works :

    <?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line">
        <stroke
            android:color="#FF404040"
            android:width="1dp"
            android:dashGap="3dp"
            android:dashWidth="1dp"
        />
        <size
            android:height="3dp"
        />
    </shape>
    
    0 讨论(0)
提交回复
热议问题