Home > Net >  How to make rounded corners for layer-list in android
How to make rounded corners for layer-list in android

Time:02-17

I want to make rounded corners for below mentioned layout:

enter image description here

I've created this drawable by using layer-list tags as:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:width="250dp"
    android:height="250dp">
    <shape android:shape="rectangle">
        <stroke
            android:width="15px"
            android:color="@android:color/transparent" />
        <solid android:color="@android:color/transparent" />
    </shape>
</item>
<item
    android:width="@dimen/margin_8"
    android:bottom="0dp"
    android:top="200dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />
    </shape>
</item>
<item
    android:width="@dimen/margin_8"
    android:bottom="200dp"
    android:top="0dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />

    </shape>
</item>
<item
    android:width="@dimen/margin_8"
    android:bottom="0dp"
    android:gravity="right"
    android:top="200dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />
    </shape>
</item>
<item
    android:width="@dimen/margin_8"
    android:bottom="200dp"
    android:gravity="right"
    android:top="0dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />
    </shape>
</item>
<item
    android:height="@dimen/margin_8"
    android:gravity="top"
    android:left="0dp"
    android:right="200dp"
    android:top="-1dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />
    </shape>
</item>
<item
    android:height="@dimen/margin_8"
    android:gravity="top"
    android:left="200dp"
    android:right="0dp"
    android:top="-1dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />
    </shape>
</item>
<item
    android:height="@dimen/margin_8"
    android:gravity="bottom"
    android:left="0dp"
    android:right="200dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />
    </shape>
</item>
<item
    android:height="@dimen/margin_8"
    android:gravity="bottom"
    android:left="200dp"
    android:right="0dp">
    <shape android:shape="rectangle">
        <solid android:color="#6fdc8c" />
    </shape>
</item>
</layer-list>

I need it like below image.

enter image description here

I have tried to add the corners tag inside shape but it didn't work. Hope my query is clear. Thanks in advance.

CodePudding user response:

try this code

  <item
        android:width="8dp"
        android:bottom="0dp"
        android:gravity="right"
        android:top="200dp">
        <shape android:shape="rectangle">
            <corners android:bottomRightRadius="10dp" />
            <solid android:color="#6fdc8c" />
        </shape>
    </item>
    <item
        android:height="8dp"
        android:gravity="bottom"
        android:left="200dp"
        android:right="0dp">
        <shape android:shape="rectangle">
            <corners android:bottomRightRadius="10dp" />
            <solid android:color="#6fdc8c" />
        </shape>
    </item>

enter image description here

CodePudding user response:

Here is the full code for your view

        <stroke
            android:width="25px"
            android:color="@android:color/transparent" />
        <solid android:color="@android:color/transparent" />

        <corners android:radius="10dp" />

    </shape>
</item>

<item
    android:width="7dp"
    android:bottom="0dp"
    android:start="0dp"
    android:top="200dp">

    <shape android:shape="rectangle">
        <corners android:bottomLeftRadius="20dp" />
        <solid android:color="#6fdc8c" />

    </shape>
</item>
<item
    android:width="7dp"
    android:bottom="200dp"
    android:top="0dp">
    <shape android:shape="rectangle">
        <corners android:topLeftRadius="20dp" />
        <solid android:color="#6fdc8c" />


    </shape>
</item>
<item
    android:width="7dp"
    android:bottom="0dp"
    android:gravity="right"
    android:top="200dp">
    <shape android:shape="rectangle">

        <corners android:bottomRightRadius="20dp" />
        <solid android:color="#6fdc8c" />
    </shape>
</item>
<item
    android:width="7dp"
    android:bottom="200dp"
    android:gravity="right"
    android:top="0dp">
    <shape android:shape="rectangle">
        <corners android:topRightRadius="20dp" />
        <solid android:color="#6fdc8c" />


    </shape>
</item>
<item
    android:height="7dp"
    android:gravity="top"
    android:left="0dp"
    android:right="200dp"
    android:top="-1dp">
    <shape android:shape="rectangle">
        <corners android:topLeftRadius="20dp" />
        <solid android:color="#6fdc8c" />


    </shape>
</item>
<item
    android:height="7dp"
    android:gravity="top"
    android:left="200dp"
    android:right="0dp"
    android:top="-1dp">
    <shape android:shape="rectangle">
        <corners android:topRightRadius="20dp" />
        <solid android:color="#6fdc8c" />

    </shape>
</item>
<item
    android:height="7dp"
    android:bottom="0dp"
    android:gravity="bottom"
    android:left="0dp"
    android:right="200dp">
    <shape android:shape="rectangle">

        <corners android:bottomLeftRadius="20dp" />


        <solid android:color="#6fdc8c" />

    </shape>
</item>
<item
    android:height="7dp"
    android:gravity="bottom"
    android:left="200dp"
    android:right="0dp">
    <shape android:shape="rectangle">
        <corners android:bottomRightRadius="20dp" />

        <solid android:color="#6fdc8c" />

    </shape>
</item>

OUTPUT

enter image description here

  • Related