0

下面是在表面上绘制的 switch case 逻辑,它不能正确绘制。不知道我哪里错了。编辑:类被删除,因为它没有帮助。

@Override
public boolean onTouchEvent(MotionEvent event) {
    synchronized (mThread.getSurfaceHolder()) {

    switch (event.getAction()) {
        case MotionEvent.ACTION_UP:

            break;

        case MotionEvent.ACTION_DOWN:
            currentDrawingPath = null;
            currentDrawingPath = new DrawingPath();
            currentDrawingPath.getPath().moveTo(eventX, eventY);
            startX = eventX;
            startY = eventY;
            canvasPaths.add(currentDrawingPath);
            //invalidate();
            break;

        case MotionEvent.ACTION_MOVE:
            float dx = Math.abs(eventX - startX);
            float dy = Math.abs(eventY - startY);
            currentDrawingPath.getPath().quadTo(startX, startY, 
                    (eventX + startX)/2, (eventY + startY)/2);
            startX = eventX;
            startY = eventY;
            //currentDrawingPath.getPath().lineTo(startX, startY);
            break;

    }
    return true;
4

1 回答 1

0

以下是解决问题的代码,

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        currentDrawingPath.getPath().lineTo(event.getX(), event.getY());
            break;
    case MotionEvent.ACTION_DOWN:
        currentDrawingPath = new DrawingPath();
        currentDrawingPath.setPaintForPath();

        // update the starting point of the new path
        currentDrawingPath.getPath().moveTo(event.getX(), event.getY());
        currentDrawingPath.getPath().lineTo(event.getX(), event.getY());
        canvasPaths.add(currentDrawingPath);
        break;
    case MotionEvent.ACTION_MOVE:
        currentDrawingPath.getPath().lineTo(event.getX(), event.getY());
        break;
    }
    return true;
于 2013-08-03T20:45:56.230 回答