[英]Dynamically draw arc
I draw an arc using onDraw(canvas)
: 我使用onDraw(canvas)
画一条弧:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
}
public class MyView extends View {
public MyView(Context context) {
super(context);
}
@Override
public void onDraw(Сanvas canvas) {
super.onDraw(canvas);
float width = (float) getWidth();
float height = (float) getHeight();
float radius;
if (width > height) {
radius = height / 4;
} else {
radius = width / 4;
}
final Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setStrokeWidth(50);
paint.setStyle(Paint.Style.STROKE);
float center_x, center_y;
center_x = width / 2;
center_y = height / 4;
final RectF oval = new RectF();
oval.set(center_x - radius, center_y - radius, center_x + radius,
center_y + radius);
paint.setStyle(Paint.Style.STROKE);
center_x = width / 2;
center_y = height * 3 / 4;
oval.set(center_x - radius, center_y - radius, center_x + radius,
center_y + radius);
canvas.drawArc(oval, -90, 45, false, paint);
}
}
Tell me, how to dynamically change the value of sweepAngle() == 45 in line canvas.drawArc(oval, -90, 45, false, paint)
? 告诉我,如何在canvas.drawArc(oval, -90, 45, false, paint)
行中动态更改sweepAngle() == 45的值?
One solution would be to have a sweepAngle
field in your class, and use that instead of 45 in drawing the arc. 一种解决方案是在您的类中具有一个sweepAngle
字段,并在绘制圆弧时使用它而不是45。 Then have a timer that periodically adds to sweepAngle
and redraws the canvas. 然后有一个计时器,该计时器会定期添加到sweepAngle
并重新sweepAngle
画布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.