Last active
September 18, 2015 09:33
-
-
Save ckdevrel/c5392c066ef76f800fc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To create a circle dynamically: | |
public static ShapeDrawable drawCircle (Context context, int width, int height, int color) { | |
ShapeDrawable oval = new ShapeDrawable (new OvalShape ()); | |
oval.setIntrinsicHeight (height); | |
oval.setIntrinsicWidth (width); | |
oval.getPaint ().setColor (color); | |
oval.setPadding (10,10,10,10); | |
return oval; | |
} | |
To draw a rectangle dynamically: | |
public static ShapeDrawable drawRectangle (Context context,int width, int height, int color) { | |
ShapeDrawable rect = new ShapeDrawable(new RectShape ()); | |
rect.setIntrinsicHeight (width); | |
rect.setIntrinsicWidth (height); | |
rect.getPaint().setColor (color); | |
return rect; | |
} | |
To draw a Rounded-rectangle dynamically: | |
public static ShapeDrawable drawRoundCornerRectange (Context context,int width, int height, float[] outerRadii, int color) { | |
ShapeDrawable rndrect = new ShapeDrawable (new RoundRectShape (outerRadii, null, null)); | |
rndrect.setIntrinsicHeight (width); | |
rndrect.setIntrinsicWidth (height); | |
rndrect.getPaint ().setColor (color); | |
return rndrect; | |
} | |
To create a Gradient drawable dynamically: | |
public static GradientDrawable setGradientColors(Context context, int bottomColor, int topColor) { | |
GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[] {bottomColor, topColor}); | |
gradient.setShape (GradientDrawable.RECTANGLE); | |
//gradient.setCornerRadius(10.f); | |
return gradient; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment