我使用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);
}
}
告诉我,如何动态更改sweepAngle() == 45的值
canvas.drawArc(oval, -90, 45, false, paint)
?
答案 0 :(得分:1)
一种解决方案是在您的类中使用sweepAngle
字段,并在绘制弧时使用该字段而不是45。然后有一个定时添加到sweepAngle
并重绘画布的计时器。