dammarpol
dammarpol

Reputation: 77

Borders for more than 2 sides in android shape

I've added border for left and top side of my custom shape with 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="#787878" />

        </shape>
    </item>

    <item android:left="1dp" android:top="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#e4e4e4" />
        </shape>
    </item>

</layer-list>

Now I would like to add different border colors for right and bottom. However when I update my code to

<?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="#787878" />
        </shape>
    </item>

    <item android:left="1dp" android:top="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#e4e4e4" />
        </shape>
    </item>

    <item android:right="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#e4e4e4" />
        </shape>
    </item>

</layer-list>

none of borders are visible, when I supposed to get borders at 3 sides. What am I doing wrong?

Upvotes: 0

Views: 2692

Answers (1)

Harin
Harin

Reputation: 2423

Here you need to add is padding to each item like this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape android:shape="rectangle" >
        <padding
            android:left="2dp"
            android:top="2dp" />

        <solid android:color="@android:color/holo_red_dark" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <padding android:right="2dp" />

        <solid android:color="@android:color/holo_blue_dark" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <padding android:bottom="2dp" />

        <solid android:color="@android:color/white" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <solid android:color="@android:color/holo_green_light" />
    </shape>
</item>

Hope it really helped!

Upvotes: 4

Related Questions