我只需绘制一条从画布的一个坐标移动到另一个坐标的线。我在绘制代码与时间同步方面遇到了麻烦。\
public class CustomMYChart extends View {
float x=0,y=0;
Canvas canvas;
Paint paint;
public CustomMYChart(Context context) {
super(context);
// TODO Auto-generated constructor stub
paint = new Paint();
paint.setColor(Color.GREEN);
}
@Override
protected void onDraw(final Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
this.canvas=canvas;
for(int i=0; i<1000; i++){
canvas.drawCircle(x, y, 5, paint);
x+=1;
y+=1;
invalidate();
}
}
}
答案 0 :(得分:0)
只需删除onDraw中的for语句,只需一次迭代即可调用1000次invalidate(),然后将x和y移出屏幕。
@Override
protected void onDraw(final Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
this.canvas=canvas;
canvas.drawCircle(x, y, 5, paint);
x+=1;
y+=1;
invalidate();
}