MREZA
MREZA

Reputation: 33

android matrix translate won't work properly

i have a problem with moving bitmap using matrix

    case MotionEvent.ACTION_MOVE:
        if (!ScaleDetector.isInProgress()) {

            speedx = (event.getX() - downCorx);
            speedy = (event.getY() - downCory);

            matrix.postTranslate(speedx, speedy);
            Log.e("000", speedx + "| " + speedy + "! ");

        }
        this.invalidate();
        break;

that code works but it Accelerates the bitmap speed!

rest of the codes:

 protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(finalBitmap, matrix, null);

    }



public void setBitmap(Bitmap bitmap) {
    finalBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    myCanvas = new Canvas(finalBitmap);
    myCanvas.drawBitmap(bitmap, 0, 0, null);
}

is there any better way to do this?

Upvotes: 0

Views: 566

Answers (1)

aschattney
aschattney

Reputation: 329

    case MotionEvent.ACTION_MOVE:
    if (!ScaleDetector.isInProgress()) {

        speedx = (event.getX() - downCorx);
        speedy = (event.getY() - downCory);

        // update your current position. So when ACTION_MOVE is triggered again, you actually calculate only the speed between the current and last event of ACTION_MOVE
        downCorx = event.getX();
        downCory = event.getY();

        matrix.postTranslate(speedx, speedy);
        Log.e("000", speedx + "| " + speedy + "! ");

    }
    this.invalidate();
    break;

Upvotes: 1

Related Questions