-3

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

4

2 回答 2

7

尝试使用下面的代码。

水平虚线.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>

垂直虚线.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"/>

结帐下面的文章了解更多详情。

如何使用 Android 可绘制对象创建垂直或水平虚线

于 2016-12-10T16:46:29.150 回答
0

更新

万一上面的 verticle.xml 不起作用试试这个。因为这对我有用。

垂直虚线.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>
于 2021-08-16T12:30:12.227 回答