1

So far, I used an ImageView (or a View, the result is the same) to draw a dotted line in my Custom ListView between each item. The xml layout is like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- Random stuff -->

    <ImageView
       android:layout_width="match_parent"
       android:layout_height="1dp"
       android:src="@drawable/dotted_line" />

</LinearLayout>

My drawable looks like:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">

    <stroke
        android:dashGap="1dp"
        android:dashWidth="1dp" />

</shape>

I tried to wrap my shape into a selector, or add android:layerType="software" in my ImageView, but nothing worked. I have also seen people suggesting to make the ImageView height bigger, or to play with the width of the dotted line. The best render I could achieve is drawing a solid line, but not the dotted line I am looking for.

Can someone help me to draw this doted line ? Should I use another method than the drawable ? Thanks!

jbiral
  • 1,431
  • 11
  • 16

0 Answers0