是否可以更改触摸事件的调用频率?

时间:2018-08-15 07:44:00

标签: android android-canvas android-view android-bitmap

我在位图上绘制路径。当我更快地移动手指时,它会画一条长线,例如MotionEvent.ACTION_MOVE会发生两次。当我试图通过快速移动手指来绘制圆线时,会出现直线。我不希望出现直线。我想画圆线。如果我缓慢地移动手指,则需要采取更多的动作,并且我会取得良好的效果。即使我快速移动手指,我也希望越来越多地调用action_move事件。是否可以更改触摸事件的调用频率?如果可以的话,我可以获得更好的输出。

private Canvas canvasBitmap;
private Bitmap bitmap;  

protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    canvasBitmap = new Canvas(bitmap);
}

protected void onDraw(Canvas canvas)
{
    canvas.drawBitmap(bitmap, 0, 0, paintDraw);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    float touchX = event.getX();
    float touchY = event.getY();

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            drawPath.moveTo(touchX, touchY);
            break;
        case MotionEvent.ACTION_MOVE:
                drawPath.lineTo(touchX, touchY);
                canvasBitmap.drawPath(drawPath, paintDraw);
            break;
        case MotionEvent.ACTION_UP:
            drawPath.lineTo(touchX, touchY);
            canvasBitmap.drawPath(drawPath, paintDraw);
            drawPath.reset();
            break;
        default:
            return false;
    }
    invalidate();
    return true;

}

0 个答案:

没有答案