微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在android studio中具有交替双色边框的形状

如何解决在android studio中具有交替双色边框的形状

我想创建一个形状用作元素的背景,因为应用程序以红色和橙色作为主要颜色,我想制作一个很酷的边框,但是我只设法找到了如何放置一个颜色,并不真正知道如何进行某种设计。 我想做这样的事情(我在油漆中快速制作,只是为了展示我的想法):

Shape with cool alternated border

解决方法

好的,我做了一些工作,并得出了一个解决方案,这并不是我想要做的,但我想它已经足够好了。这是放在drawable文件夹中的xml文件中的代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape
            android:shape="rectangle"
            android:padding="10dp">
            <solid android:color="#FFFFFF"/>
            <corners
                android:bottomRightRadius="20dp"
                android:bottomLeftRadius="20dp"
                android:topLeftRadius="20dp"
                android:topRightRadius="20dp"/>

            <stroke
                android:width="10dp"
                android:color="@color/colorAccent"/>
        </shape>
    </item>
    <item>
        <shape
            android:shape="rectangle"
            android:padding="10dp">
            <corners
                android:bottomRightRadius="20dp"
                android:bottomLeftRadius="20dp"
                android:topLeftRadius="20dp"
                android:topRightRadius="20dp"/>

            <stroke
                android:width="8dp"
                android:color="@color/colorPrimary"
                android:dashGap="10dp"
                android:dashWidth="8dp" />
        </shape>
    </item>
</layer-list>

这段代码会产生这样的结果:

shape with bicolor border

希望对大家有帮助

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。