Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android shape border with gradient

I want to create a border for a linearLayout. So I decide to create a shape. I want the border to have a gradient. The following is not doing it. It fills the rectangle and then creates a stroke. I don't want a filled rectangle, just the stroke. And I want to apply the gradient to the stroke.

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle" >      <gradient         android:angle="360"         android:centerColor="#e95a22"         android:endColor="#ff00b5"         android:gradientRadius="360"         android:startColor="#006386"         android:type="sweep" />      <stroke         android:width="2dp"         android:color="#ff207d94" />  </shape> 
like image 595
learner Avatar asked Jan 01 '14 16:01

learner


1 Answers

try something like this:

<?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >      <item>         <shape android:shape="rectangle" >             <gradient                 android:angle="360"                 android:centerColor="#e95a22"                 android:endColor="#ff00b5"                 android:gradientRadius="360"                 android:startColor="#006386"                 android:type="sweep" />              <stroke                 android:width="2dp"                 android:color="#ff207d94" />         </shape>     </item>     <item         android:bottom="2dp"         android:left="2dp"         android:right="2dp"         android:top="2dp">         <shape android:shape="rectangle" >             <solid android:color="#fff" />         </shape>     </item>  </layer-list> 
like image 104
vipul mittal Avatar answered Sep 28 '22 00:09

vipul mittal