Create gradient border in android?

How can I create a gradient border like in the image below?

Answers


You can achieve this by using a layerlist and messing with the padding. You'll need 3 elements:

1: A border.xml shape, which is just a solid shape in the color of your border: border.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ff0000"/>
</shape>

2: The 'inner' shape, the shape where you want the border to appear around: inner.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00ff00"/>
</shape>

3: A layer list, which will put these 2 on top of eachother. You create the border by setting the padding on the inner shape: layerlist.xml

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/border"/>
<item android:drawable="@drawable/inner"

Specify here where you want to have a stroke(top, left, right, bottom)

android:top="3dp" android:right="0dp" android:bottom="3dp"
android:left="3dp" />

Set this as the background of your TextView, Layout etc. (where you want the stroke to appear)

Or just create a 9Patch image with the borders.


Need Your Help

Zend_Soap_Server/Client doesn't work. Returns "looks like we got no XML document"

php soap zend-framework

I am working with Zend Framework, and I need to make a web service using Zend_Soap. After searching for 3 days, I've decided to ask myself. After creating Zend_Soap_Server i get message