0

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

我的 Drawable 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"/>
4

1 回答 1

1

如果您的View不起作用,请尝试使用ImageView它正在工作

 <ImageView
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:src="@drawable/dotted_line"
    android:layout_marginTop="5dp"
    android:layerType="software" />
于 2017-09-25T08:59:17.830 回答