Draw an arc using SweepGradient in Android

How to draw an arc using a shader like SweepGradient?

In the examples that I have, there is a Paint object:

Paint lightRed = new Paint();
lightRed.setAntiAlias(true);
lightRed.setStyle(Style.STROKE);
lightRed.setStrokeWidth(12);
lightRed.setColor(0xFFCC0000);
...
canvas.drawArc(rectf, -90, 360, false, lightRed);

Do not think that it matters, but I use it to draw as a desktop widget.

+5
source share
1 answer

Try the following:

Shader gradient = new SweepGradient (0,getMeasuredHeight()/2, Color.RED, Color.WHITE);
lighted.setShader(gradient);
canvas.drawArc(rectf, -90, 360, false, lightRed);

You can change the position and color values.

+11
source

All Articles