Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create vertical gradient in android

Tags:

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

like image 900
Hunt Avatar asked Mar 03 '12 16:03

Hunt


People also ask

What is gradient drawable?

Designers are trying out different styles and combinations which go best with the Android App. One of the key components of Android being used these days is called GradientDrawable. A GradientDrawable is drawable with a color gradient for buttons, backgrounds, etc.

What is angle in gradient?

Gradient basically represents the variation in space(in a direction) of any quantity. With color it represents the variation of color intensity in a direction represented by angle. Here are some diagrams to represent this concept: Here the figure shows the color variation in horizontal direction (angle is set 0).


2 Answers

Use

android:angle="270" 

as another attribute in your gradient

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

like image 137
Rahul garg Avatar answered Sep 24 '22 09:09

Rahul garg


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

like image 23
the100rabh Avatar answered Sep 25 '22 09:09

the100rabh