Draw a circle in canvas with several gradient colors.

I need to draw a circle in an Android canvas based on a gradient list of colors. I managed to draw it without a gradient, like a set of arcs, each of which has one of the colors in the list, as shown in the following image.

enter image description here

How can I draw it using the actual gradient? I tried using the following code to apply a shader to paint:

Shader shader = new LinearGradient(0, 0, circleWidth, circleHeight, colorList, null, Shader.TileMode.MIRROR); paint.setShader(shader); canvas.drawCircle(circleWidth / 2, circleHeight / 2, radius, paint); 

but the result is as follows.

enter image description here

+5
source share
1 answer

I managed to do this with SweepGradient.

 Shader shader = new SweepGradient(circleWidth / 2, circleHeight / 2, colorList, null); paint.setShader(shader); canvas.drawCircle(circleWidth / 2, circleHeight / 2, radius, paint); 

enter image description here

+1
source

All Articles