1

I have a ShapeDrawable Object in my class in the form of an arc.

ShapeDrawable progressArc = new ShapeDrawable(new ArcShape(120, 12));

Now I would like to use a radial gradient effect on the color and also display just a ring instead of a filled arc. Does the Android SDK provide such a feature?

Currently using the below code, I get a gradient on the circle.

progressArc.setIntrinsicHeight(500);
progressArc.setIntrinsicWidth(500);

Shader shader1 = new LinearGradient(5, -5, 35, 0, new int[] { 0xFF33B5E5,0xFFFFFFFF }, null, Shader.TileMode.MIRROR);
progressArc.getPaint().setShader(shader1);
progressArc.getPaint().setStrokeWidth(1);
progressArc.getPaint().setColor(Color.RED);
progressArc.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);
Daniel Compton
  • 13,878
  • 4
  • 40
  • 60
Ahmed Faisal
  • 4,397
  • 12
  • 45
  • 74

1 Answers1

4

You can use a SweepGradient to get a radial gradient:

Shader s = new SweepGradient(0, 0, new int[] { 0xFF33B5E5,0xFFFFFFFF }, null);
//or if you only use two colors:
Shader s = new SweepGradient(0, 0, 0xFF33B5E5, 0xFFFFFFFF);

To avoid filling, just use the Paint.Style.STROKE style, with appropriate strokeWidth.

Jave
  • 31,598
  • 14
  • 77
  • 90