我无法弄清楚如何实现LinearGradient,以便我可以使用像
这样的渐变来绘制填充也许我会以错误的方式解决这个问题?
canvas.drawArc(rectF, startPosInDegrees, angle, false, foregroundPaint);
我试图将LinearGradient实现为“foregroundPaint”并在圆周上绘制一个新的LinearGradient。
如何实现上述结果?
我的上述代码基于以下代码:
https://android-arsenal.com/details/1/3186
我刚刚添加了以下内容,完全是foo-bar:
public void setLinearGradientPaintWithAngle(Paint paint, float left, float top,
float right, float bottom, int[] colors2) {
double angle = 90;
double angleInRadians = Math.toRadians(angle);
double length = 100; //Don't know what this is yet.
double rightWithAngle = Math.cos(angleInRadians) * right;
double bottomWithAngle = Math.sin(angleInRadians) * bottom;
LinearGradient linearGradient = new LinearGradient(left, top, (float) rightWithAngle, (float) bottomWithAngle, colors2, null, TileMode.CLAMP);
paint.setShader(linearGradient);
paint.setAntiAlias(true);
}
谢谢!