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

时间:2017-07-28 09:10:02

标签: android xml

我创建了一个像这样的XML drawable a part from the image

,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中的预览。当图像在模拟器中显示时,它显示单行而不是虚线。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

将此行添加到ImageView布局

中的xml
android:layerType="software"