在 android 中添加水平和垂直虚线

Adding horizontal and vertical dotted lines in android

请给我在列表中添加垂直虚线的代码view.I已尝试使用形状标记方法创建xml

尝试使用以下代码。

horizontal_dashed_line.xml

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

vertical_dashed_line.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:toDegrees="90"
    android:drawable="@drawable/horizontal_dashed_line"/>

用法:

<View
    android:layout_width="4dp"
    android:layout_height="300dp"
    android:background="@drawable/horizontal_dashed_line"/>

查看下面的文章了解更多详情。

How to create vertical or horizontal dashed lines with Android drawables

更新

InCase the above verticle.xml not worked TRY this one. AS this Worked for me.

vertical_dashed_line.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:left="-600dp"
    android:right="-600dp">
    <rotate
      android:drawable="@drawable/horizontal_dashed_line"
      android:fromDegrees="90"
      android:visible="true" />
  </item>
</layer-list>