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>
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.
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).
A Drawable with a color gradient for buttons, backgrounds, etc. It can be defined in an XML file with the <shape> element.
A GradientDrawable is drawable with a color gradient for buttons, backgrounds, etc.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With