防止形状可画中风的部分重叠

Moh*_*tif 9 android android-shapedrawable

有没有什么办法来防止部分重叠strokeshape drawable.我更喜欢在形状的边界上完全重叠笔画.

这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <padding
        android:bottom="0dp"
        android:top="0dp"
        android:left="0dp"
        android:right="0dp" />
    <solid android:color="@color/green" />
    <stroke android:color="@color/red_50"
        android:width="20dp"
        android:dashGap="2dp"
        android:dashWidth="10dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)

colors.xml

<color name="green">#0f0</color>
<color name="red_50">#8f00</color>
Run Code Online (Sandbox Code Playgroud)

这是实现的目标
示例图像

正如您所看到的那样,笔划与实体部分重叠了50%,但我希望它是100%.

pau*_*lab 8

尝试将其分为两种形状 - 一种用于笔划,另一种用于矩形.在这个解决方案中,我操纵矩形的大小,以便我可以改变它与边界的关系.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:bottom="@dimen/offset"
        android:left="@dimen/offset"
        android:right="@dimen/offset"
        android:top="@dimen/offset">

        <shape android:shape="rectangle">
            <solid android:color="@color/green" />
        </shape>

    </item>

    <item>

        <shape android:shape="rectangle">
            <stroke
                android:width="20dp"
                android:color="@color/red_50"
                android:dashGap="2dp"
                android:dashWidth="10dp" />
        </shape>

    </item>

</layer-list>
Run Code Online (Sandbox Code Playgroud)

您可以调整偏移量以获得外部或内部笔划.

外部和内部中风

这些值来自透明矩形(笔划层)和绿色矩形的大小差异.在你的情况下,他们将是20dp或没有.