毫无疑问,我正在做一些愚蠢的事,但我似乎无法发现它。我试图根据用户的触摸绘制路径。捕获这些单独触摸的代码是:
public boolean onTouch(View view, MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// The user is starting a new path
Path path = new Path();
paths.push(path);
path.moveTo(x,y);
path.lineTo(x,y);
break;
case MotionEvent.ACTION_MOVE:
// The user is drawing on the current path
path = paths.getLast();
path.quadTo(x,y, (lastX + x)/2f, (lastY + y)/2f);
break;
}
lastX = x;
lastY = y;
invalidate();
return true;
}
然后绘制线条:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
ListIterator<Path> iterator = paths.listIterator();
while (iterator.hasNext()) {
Path path = iterator.next();
canvas.drawPath(path, paint);
}
}
问题是,当我开始绘制第二个(或第n个)路径时,代码在最后一个端点和当前端点之间添加一条线。有什么建议吗?
由于