我想在我的绘图应用程序中记录用户的输入。它可以画出任何他想要的东西,而不仅仅是直线形状。我怎样才能在一条路径上记录用户在绘制时所做的所有动作,例如,一个特定的圆圈?这是我的方法,其中有System.out.println()是我将推送方法以保存路径的地方。
public boolean onTouchEvent(MotionEvent event) {
float touchX = event.getX();
float touchY = event.getY();
//respond to down, move and up events
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
drawPath.moveTo(touchX, touchY);
break;
case MotionEvent.ACTION_MOVE:
drawPath.lineTo(touchX, touchY);
break;
case MotionEvent.ACTION_UP:
drawPath.lineTo(touchX, touchY);
System.out.println(touchX +", " +touchY);
drawCanvas.drawPath(drawPath, drawPaint);
drawPath.reset();
break;
default:
return false;
}
//redraw
invalidate();
return true;
}```
largeQ
相关分类