Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

xml - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...