Search code examples
androidlayoutbackgroundshapes

How to make a rectangle with inverted rounded corners?


I know how to make rectangle with rounded corners, like this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid
        android:color="#FF0000"/>
    <corners
        android:radius="10000dp" />
</shape>

It looks like this:

enter image description here

But I want to make the inverse of that (center transparent and sides filled with color), which should look like this:

enter image description here

Thanks


Solution

  • Not proper way, but will get the result, try

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape android:shape="rectangle">
                <padding
                    android:bottom="-100dp"
                    android:left="-100dp"
                    android:right="-100dp"
                    android:top="-100dp" />
            </shape>
        </item>
        <item>
            <shape android:shape="rectangle">
                <corners android:radius="200dp" />
                <stroke
                    android:width="100dp"
                    android:color="#FF0000" />
            </shape>
        </item>
    </layer-list>