Draw an arc with a SweepGradient in Android

[亡魂溺海] 提交于 2019-12-04 12:01:28

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4786318/draw-an-arc-with-a-sweepgradient-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!