Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GradientDrawable change angle programmatically

Tags:

android

I have following xml for GradientDrawable. How can I change the angle programmatically?

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:type="linear" 
       android:angle="45" 
       android:startColor="#FF0000" 
       android:endColor="#00FF00" />
</shape>
like image 724
AndroidDev Avatar asked Apr 29 '15 06:04

AndroidDev


People also ask

How do you change the gradient of an angle in Android?

The angle of the gradient can be set using the android:angle attribute using the Integer value representing the angle in degrees. This value must be a multiple of 45. A value of 0, which is the default value, represents an angle of left to right, a value of 90 represents an angle of bottom to top.

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).

What is GradientDrawable in android?

A Drawable with a color gradient for buttons, backgrounds, etc. It can be defined in an XML file with the <shape> element.

What is GradientDrawable?

A GradientDrawable is drawable with a color gradient for buttons, backgrounds, etc.


1 Answers

GradientDrawable has a method called: .setOrientation(GradientDrawable.Orientation orientation), you can change the orientation of a gradient with this. You need to inflate the XML as GradientDrawable.

like image 75
Tim Kranen Avatar answered Sep 18 '22 17:09

Tim Kranen