美文网首页
Android 在drawable中绘制复杂图形

Android 在drawable中绘制复杂图形

作者: 光羽隼 | 来源:发表于2018-10-24 17:20 被阅读0次

    使用layer-listshape组合

    今天要做一个两个圆环嵌套的图形,类似于这样

    双圆环
    不想写两个shape,那就使用layer-list创建shape的组合吧。
    本来我是这样写的
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="oval">
                <stroke
                    android:width="4px"
                    android:color="@color/white" />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <stroke
                    android:width="4px"
                    android:color="#fb484a" />
            </shape>
        </item>
    </layer-list>
    

    结果是这样的,

    错误示范
    这种只显示最后一个形状,也就是说最后创建的shape压住了之前的白色圆形,这时候我们需要使用到shape中的padding属性
    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="oval">
                <stroke
                    android:width="4px"
                    android:color="@color/white" />
    
                <padding android:bottom="10px" android:left="10px" android:right="10px" android:top="10px"/>
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <stroke
                    android:width="4px"
                    android:color="#fb484a" />
            </shape>
        </item>
    </layer-list>
    

    这样在第一个shape中写了padding属性之后,以后的shape就只能在padding限定的区域活动了
    结果

    结果

    Vector绘图


    vector不错的博客

    相关文章

      网友评论

          本文标题:Android 在drawable中绘制复杂图形

          本文链接:https://www.haomeiwen.com/subject/ztjxtqtx.html