毫无疑问,我在做一些愚蠢的事情,但我似乎无法发现它。我正在尝试根据用户触摸绘制路径。捕获这些单独触摸的代码是:
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 条)路径时,代码会在最后一条的端点和当前路径的开头之间添加一条线。有什么建议么?
谢谢