Create A Radial Gradient Programmatically
Im trying to reproduce the following gradient programmatically.
Solution 1:
http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html
To set that specific parameter (I'm assuming a centerX value as you haven't specified one):
yourGradientDrawable.setGradientCenter(1.0f, 0.45f);
So to create the above gradient (except with different colors) programatically:
GradientDrawable g = newGradientDrawable(Orientation.TL_BR, newint[] { getResources().getColor(R.color.startcolor), Color.rgb(255, 0, 0), Color.BLUE });
g.setGradientType(GradientDrawable.RADIAL_GRADIENT);
g.setGradientRadius(140.0f);
g.setGradientCenter(0.0f, 0.45f);
Note: The orientation is ignored for a radial gradient but is needed for the constructor that takes colors.
Post a Comment for "Create A Radial Gradient Programmatically"