24

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

2

2 Answers 2

71

Use

android:angle="270"

as another attribute in your gradient

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

Sign up to request clarification or add additional context in comments.

9 Comments

garg i tried android:startColor="#FFFFFF" android:centerColor="#F52578" android:endColor= "#FFFFFF" android:angle="270" but its not working
the gradient you mentioned is correct,, how are you using it in the view... ` android:layout_height="1.0px"` not this right... that would make the height 1 px..and you won't see gradient... What is the current color of the view visible..?
These are the attributes of view android:background="@drawable/divider_gradient" android:layout_width="1dp" android:layout_height="fill_parent"
is view showing up at all..? try changing android:background="#FFF", and notice if the view is visible at all of complete white background.. if yes then you can change that to gradient.. otherwise problem is in you view position and size...
gard i tried your code only actually gradient wasn't visible in emulator , but was showing in a real device , so +1 for showing your interest
|
1

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

1 Comment

what angle did u try working with ?? Also try changing that width to something like 4dp for trials first instead of 1.0px, and I would suggest u to use 1dp instead of 1px always

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.