开发者

90 Degrees Radial Gradient in Android

I am working on a custom View that shows a (round) gauge. I would like to make the background of the scale to go from green to yellow to red (270 degree scale) to black. The problem I am facing is that I can not figure out how to make a 90 degree radial gradient - to be specific I would like to draw a gradient that goes from green to yellow radially in 90 degrees (and then from yellow to red (in 90 degrees) and from red do back (again in 90 degrees)). My current code looks like:

canvas.drawOval(scaleRect, scalePaint);

canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.rotate(-135, 0.5f, 0.5f);

paintSection.setShader(new RadialGradient(0.0f, 0.0f, 1.0f,
Color.GREEN, Color.YELLOW, Shader.TileMode.REPEAT));
canvas.drawArc(scaleRect, -90, 90, true, paintSection);

canvas.rotate(90, 0.5f, 0.5f);

paintSection.setShader(new RadialGradient(0.0f, 0.0f, 1.0f,
Color.YELLOW, Color.RED, Shader.TileMode.MIRROR));
canvas.drawArc(scaleRect, -90, 90, true, paintSection);

canvas.rotate(90, 0.5f, 0.5f);

paintSection.setShader(new RadialGradient(0.0f, 0.0f, 1.0f, Co开发者_如何转开发lor.RED,
Color.BLACK, Shader.TileMode.MIRROR));
canvas.drawArc(scaleRect, -90, 90, true, paintSection);

canvas.restore();

and does not produce the required look. Thank you in advance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜