形状虚线,破折号无效

Art*_*tem 4 android android-shape

我想使用制作虚线shape

这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="line">
            <stroke android:color="@color/grey_divider"
                android:width="1dip"
                android:dashWidth="5dip"
                android:dashGap="13dip"/>
        </shape>
    </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

在我的设备上,我看到以下内容: 在此处输入图片说明 但是我需要这样的东西:

在此处输入图片说明

如何解决?

san*_*mar 5

尝试这个

在drawable中制作一个xml文件。(例如dashed_line.xml)

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">

    <stroke
       android:color="#C7B299"
       android:dashWidth="10px"
       android:dashGap="10px"
       android:width="1dp"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

现在,在您的布局中使用此xml文件。

android:background="@drawable/dashed_line"
Run Code Online (Sandbox Code Playgroud)

  • &lt;ImageView android:layout_width="match_parent" android:layout_height="3dp" android:src="@drawable/dotted_line" android:layerType="software" /&gt; (2认同)
  • android:layerType="software" - 只有这一行对我有帮助,即使是我的 XML。请写成答案 (2认同)