如果我的代碼是這樣的,我將如何刪除畫布上繪製的圖像?我在哪裏將刪除過程放在這裏?我試過使用canvas.drawColor(Color.BLACK);
,但它不工作。如何刪除Canvas中繪製的圖像?
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
return true;
case MotionEvent.ACTION_MOVE:
path.lineTo(eventX, eventY);
break;
case MotionEvent.ACTION_UP:
// nothing to do
break;
default:
return false;
}
// Schedules a repaint.
invalidate();
return true;
}
}
它是在這個代碼之後?公共SingleTouchEventView(上下文上下文,AttributeSet attrs){super(context,attrs); – user1081908
謝謝!它幫助:) – nithinreddy