Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Create gradient border?

I know it's frustrating after all similar posts at stackoverflow. I've surfed a lot of posts but i really couldn't solve my problem. So please help! I want to set a gradient border via xml like the image:

enter image description here

How can i achieve this?

like image 870
saraX Avatar asked May 28 '16 07:05

saraX


1 Answers

Customized as per your design, create a drawable file:

 <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="8px">
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#08000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="3px"
                        android:left="3px"
                        android:right="3px"
                        android:top="3px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#09000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="2px"
                        android:left="2px"
                        android:right="2px"
                        android:top="2px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#10000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="2px"
                        android:left="2px"
                        android:right="2px"
                        android:top="2px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#11000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="1px"
                        android:left="1px"
                        android:right="1px"
                        android:top="1px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#12000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="1px"
                        android:left="1px"
                        android:right="1px"
                        android:top="1px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#13000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="1px"
                        android:left="1px"
                        android:right="1px"
                        android:top="1px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#14000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="1px"
                        android:left="1px"
                        android:right="1px"
                        android:top="1px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#15000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="1px"
                        android:left="1px"
                        android:right="1px"
                        android:top="1px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#16000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="1px"
                        android:left="1px"
                        android:right="1px"
                        android:top="1px" />
                </shape>
            </item>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="#17000000" />
                    <corners android:radius="4dp" />
                    <padding
                        android:bottom="1px"
                        android:left="1px"
                        android:right="1px"
                        android:top="1px" />
                </shape>
            </item>
        </layer-list>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFF" />
            <corners android:radius="4dp" />
            <padding
                android:bottom="15dp"
                android:left="15dp"
                android:right="15dp"
                android:top="15dp" />
        </shape>
    </item>
</layer-list>

And set as background of your layout

like image 129
Milan Pansuriya Avatar answered Sep 28 '22 17:09

Milan Pansuriya