0

I'm trying to replicate the following shape in Android studio:

enter image description here

I can't figure out how to do it in android drawable xml.

At the moment I used a layer-list where: As the first item I placed a transparent (or white) rectangle, to which I gave a padding on the left side and vertically. As the second item I placed a rectangle containing the gradient and the corners on the left.

Now, I don't know how I can make the two "reverse angles" on the right, I've tried everything but online there aren't many examples to refer.

Here's my current code:

<?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="@color/transparent" />
                    <padding
                        android:bottom="8dp"
                        android:left="8dp"
                        android:right="0dp"
                        android:top="8dp" />
                </shape>
            </item>

            <item>
                <shape android:shape="rectangle">

                    <gradient
                        android:angle="0"
                        android:endColor="@color/green"
                        android:startColor="@color/blue"
                        android:type="linear" />
                    <corners
                        android:bottomLeftRadius="22dp"
                        android:bottomRightRadius="0dp"
                        android:topLeftRadius="22dp"
                        android:topRightRadius="0dp" />
                </shape>
            </item>

</layer-list>

How can I change the code to obtain this shape?

L. Gangemi
  • 3,110
  • 1
  • 22
  • 47

1 Answers1

1
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:width="600dp"
        android:height="400dp">
        <shape android:shape="rectangle">

            <gradient
                android:angle="0"
                android:endColor="@android:color/holo_green_light"
                android:startColor="@android:color/holo_blue_light"
                android:type="linear" />
        </shape>
    </item>


    <item android:width="600dp"
        android:height="100dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <corners android:bottomRightRadius="100dp" />
        </shape>
    </item>

    <item android:width="600dp"
        android:height="100dp"
        android:top="300dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <corners android:topRightRadius="100dp" />
        </shape>
    </item>

    <item android:width="200dp"
        android:height="200dp"
        android:top="100dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
        </shape>
    </item>

    <item android:width="600dp"
        android:height="200dp"
        android:top="100dp">
        <shape android:shape="rectangle">
            <gradient
                android:angle="0"
                android:endColor="@android:color/holo_green_light"
                android:startColor="@android:color/holo_blue_light"
                android:type="linear" />
            <corners android:radius="100dp" />
        </shape>
    </item>

</layer-list>

Here is a preview image


try this

Ashton Yoon
  • 172
  • 2
  • 6
  • The shape is right, but It doesn't work with the fixed height and width. When I use this drawable as background for a textview, it forces his height and width. I could change those values but I want the drawable to be usable in different places – L. Gangemi Feb 15 '21 at 12:37
  • 1
    Can you check this? https://stackoverflow.com/questions/6061387/android-drawable-specifying-shape-width-in-percent-in-the-xml-file It may be helpful for you – Ashton Yoon Feb 15 '21 at 13:15