请在下面找到我的 onDraw 方法的代码(。我正在尝试在绘制圆弧后将画布(//Rotate call -b)旋转 25 度。但我发现圆弧仍然是从 0 到 50 度绘制的。我原以为它会再移动 25 度。
public class CustomView extends View {
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.RED);
int px = getMeasuredWidth() / 2;
int py = getMeasuredHeight() / 2;
// radius - min
int radius = 130;
// Defining bounds for the oval for the arc to be drawn
int left = px - radius;
int top = py - radius;
int right = left + (radius * 2);
int bottom = top + (radius * 2);
RectF rectF = new RectF(left, top, right, bottom);
paint.setColor(Color.RED);
paint.setStyle(Style.FILL);
//canvas.rotate(25,px,py);//Rotate call -a
canvas.drawArc(rectF, 0, 50, true, paint);
canvas.rotate(25,px,py);//Rotate call -b
}
}
但是,如果我在绘制圆弧之前放置旋转调用(//Rotate call -a),我会看到绘制的圆弧移动了 25 度以上。这里到底发生了什么?有人可以向我解释吗?
谢谢