Android creates radius for rounded corners for smaller shapes only at left

906 Views Asked by At

I set android:radius="20dp" but why rounded corners only at the left? Red shape should also have rounded corners at the right as well

<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

Updated

I want to achieve the next background for EditText

enter image description here

We can set width for item (for first left shape) but it's only available from 23+ API, I need to support 21+

I have a solution for 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

2

There are 2 best solutions below

3
On

You can try the following, the right side also has a corner radius now.

<?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>

It gives the following result

enter image description here

3
On

Invisible because of being covered.

<?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