Hunt
Hunt

Reputation: 8425

create vertical gradient in android

I want to create vertical gradient separator in android

I am able to create for horizontal separator but in vertical gradient nothing appears

code for horizontal

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
       <gradient       
                android:startColor="#DEDEDE"
                android:centerColor="#F52578"
                android:endColor=  "#DEDEDE"
      /> 
</shape>

this is how i use in my project

  <View 
            android:background="@drawable/divider_gradient"
            android:layout_width="fill_parent"
            android:layout_height="1.0px"

     />

i tried layout_width="1dp" and layout_height="fill_parent" for vertical separator but nothing appears

Upvotes: 24

Views: 28841

Answers (2)

Rahul garg
Rahul garg

Reputation: 9362

Use

android:angle="270"

as another attribute in your gradient

to get you start color - center color - end color as Top to Bottom

Upvotes: 71

the100rabh
the100rabh

Reputation: 4147

Make use of Angle attribute to achieve gradient in wanted direction. More at http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

Upvotes: 1

Related Questions