Android Xml drawable无法在应用程序中正确显示

Android Xml drawable无法在应用程序中正确显示,android,xml,Android,Xml,我创建了一个如下所示的XML绘图 xml是 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:top="5dp"> <shape android:dither="true" android:shape="rectangle"> <

我创建了一个如下所示的XML绘图

xml是

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:top="5dp">
        <shape
            android:dither="true"
            android:shape="rectangle">
            <solid android:color="@color/cardview_light_background" />
        </shape>
    </item>

    <item
        android:gravity="top"
        android:top="2dp">
        <shape android:shape="line">
            <size android:height="2dp" />
            <stroke
                android:width="1dp"
                android:color="@color/colorAccent"
                android:dashGap="48dp"
                android:dashWidth="@dimen/activity_default_margin" />
        </shape>
    </item>

    <item
        android:gravity="top"
        android:left="32dp"
        android:top="2dp">
        <shape android:shape="line">
            <size android:height="2dp" />
            <stroke
                android:width="1dp"
                android:color="#f9607d"
                android:dashGap="48dp"
                android:dashWidth="@dimen/activity_default_margin" />
        </shape>
    </item>

</layer-list>


上面的图片来自android studio的预览。当图像显示在emulator中时,它会显示一条直线,而不是虚线。我如何解决这个问题

将此行添加到
xml
布局中的
ImageView

android:layerType="software"

你如何使用这个可绘图工具?@PhátPhát像往常一样
android:background=“@drawable/image”
试试下面的解决方案