prevent partial overlapping of shape drawable stroke

前端 未结 1 1520
时光取名叫无心
时光取名叫无心 2021-02-15 01:24

Is there any way to prevent partial overlapping of the stroke on the shape drawable. I prefer to overlap the stroke completely on the borders of the sh

相关标签:
1条回答
  • 2021-02-15 02:19

    Try to divide it into two shapes - one for stroke and one for rectangle. In this solution I manipulate size of rectangle so that I can change its relation with borders.

    <?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>
    

    You can adjust the offset to get outer or inner stroke.

    These values come from difference of size of transparent rectangle (stroke layer) and the green one. In your case they will be 20dp or none.

    0 讨论(0)
提交回复
热议问题