Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw an arc with a SweepGradient in Android

How can I draw an arc using a Shader such as SweepGradient?

The examples I have all take 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);

Don't think it makes a difference, but I'm using it to draw to a homescreen widget

like image 390
pufferfish Avatar asked Jan 24 '11 19:01

pufferfish


1 Answers

Try this:

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

You can modify the position and color values.

like image 164
Ganesh kumar Avatar answered Sep 19 '22 21:09

Ganesh kumar