Android 仅在左侧为较小形状的圆角创建半径

问题描述

我设置了 android:radius="20dp" 但为什么圆角只在左边?红色形状的右侧也应该有圆角

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#c61b1f" />
            <corners
                android:radius="20dp"/>
            <padding android:left="60dp" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#eeeeee" />
        </shape>
    </item>
</layer-list>

enter image description here

更新

我想实现EditText的下一个背景

enter image description here

我们可以为 width 设置 item(用于第一个左形状)但它只能从 23+ API 中使用,我需要支持 21+

我有一个适用于 23+ API 的解决方案:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item> 
    // white shape
        <shape android:shape="rectangle">
            <solid android:color="#eeeeee" />
            <corners android:radius="20dp"/>
        </shape>
    </item> 
    // red shape
    <item android:width="60dp">
        <shape android:shape="rectangle">
            <solid android:color="#c61b1f" />
            <corners
                android:radius="20dp"/>
        </shape>
    </item>
</layer-list>

enter image description here

解决方法

您可以尝试以下方法,右侧现在也有圆角半径。

<?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="20dp"/>
            <solid android:color="#eeeeee" />
        </shape>
    </item>

    <item android:right="340dp">
        <shape android:shape="rectangle">
            <solid android:color="#c61b1f" />
            <corners
                android:radius="20dp"/>
        </shape>
    </item>
</layer-list>

结果如下

enter image description here

,

因为被遮盖而看不见。

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

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...