【问题标题】:Layer Drawable/Layer list is not drawing shapes on top of each other图层可绘制/图层列表未在彼此之上绘制形状
【发布时间】:2021-05-18 00:25:15
【问题描述】:

我正在尝试创建一个带有黄色环的圆形按钮。我正在尝试将图层列表用作可绘制资源文件,并在背景中使用圆形按钮,在顶部使用环。

但是,无论我尝试什么,圆环都没有画在圆的顶部。只有圆圈出现。

    <?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="16dp"/>
            <solid android:color="@color/blue_button"/>
            <size android:width="32dp" android:height="32dp"/>
        </shape>
    </item>
    <item>
        <shape android:shape="ring" android:innerRadius="50dp" android:useLevel="false" android:thickness="16dp">
            <solid android:color="@color/black"/>
        </shape>
    </item>
</layer-list>

当我尝试隔离环形时,我可以看到它。但是当我把它和圆圈结合起来时,我看到的只是圆圈。调整粗细或 innerRadius 似乎没有帮助。

我不确定我在这里做错了什么。戒指是最后画的,所以它应该在上面。有人可以帮忙吗?

【问题讨论】:

    标签: android button layer-list layerdrawable


    【解决方案1】:

    你可以试试这个吗:

    <layer-list
    xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <item android:height="50dp" android:width="50dp" android:gravity="center">
        <shape
            android:shape="oval">
            <solid
                android:color="#2323ff"/>
        </shape>
    </item>
    <item android:height="48dp" android:width="48dp" android:gravity="center">
        <shape
            android:shape="oval"  >
            <solid
                android:color="#000000"/>
        </shape>
    </item>
    </layer-list>
    

    【讨论】:

    • 这可行,但最终我需要在按钮和环之间留出空隙。所以两个椭圆重叠是行不通的。你知道为什么我的“矩形”(圆形)形状不适用于戒指吗?
    • 你能发布你需要的最终截图吗?
    • 类似this。我打算创建一个黄色环向外跳动的动画。所以我需要为每个帧创建多个可绘制对象来创建这种效果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-01
    • 2020-05-31
    • 1970-01-01
    • 1970-01-01
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多