问题描述
我设置了 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>
更新
我想实现EditText
的下一个背景
我们可以为 width
设置 item
(用于第一个左形状)但它只能从 23+ API 中使用,我需要支持 21+
<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>
解决方法
您可以尝试以下方法,右侧现在也有圆角半径。
<?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>
结果如下
,因为被遮盖而看不见。
<?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>