xml android 中显示的是平面线而不是虚线

Plane line showing instead of Dotted line in xml android

我试图在我的视图中显示虚线“---”。我在 Whosebug 上搜索了许多示例,并使用类似的可绘制代码并调用了我的视图。在我的 IDE 上它显示虚线但是当我在我的设备上 运行 它显示平面直线。请在这方面建议我为什么会这样。

我的可绘制对象dotted.xml

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

我调用它的视图。

 <View
        android:layout_width="fill_parent"
        android:layout_height="10dp"
        android:background="@drawable/dotted_line"
        android:layout_marginTop="5dp"/>

如果您的 View 无法正常工作,请尝试使用 ImageView 它可以正常工作

 <ImageView
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:src="@drawable/dotted_line"
    android:layout_marginTop="5dp"
    android:layerType="software" />