5

I looked on many posts but couldnt find the answer. I would like to rotate an root image with another small image that is located on the lower side of the root image.

while rotation its working but the first time I press it, it jumps to 45 degrees because of the math.tan(), I think I have a calculation problem.

       rotateImage.setOnTouchListener(new OnTouchListener() {

    @Override

public boolean onTouch(View view, MotionEvent event) {

final int action = MotionEventCompat.getActionMasked(event);

        switch (action) {
        case MotionEvent.ACTION_UP:
        break;
        case MotionEvent.ACTION_DOWN:

        rotateX = event.getRawX() - rotateImage.getWidth() / 2;
        rotateY = event.getRawY() - rotateImage.getHeight() / 2;


        break;

        case MotionEvent.ACTION_MOVE:

        float angle = (float) Math.toDegrees(Math.atan2(event.getRawY() - rotateY, event.getRawX() - rotateX));

        if (angle < 0){
        angle += 360;
        }

        mBinding.getRoot().setRotation(angle);


        }

        return true;
        }
        });

please advice.

joseRo
  • 1,337
  • 3
  • 18
  • 35

1 Answers1

4

I think this library can help you. https://github.com/kencheung4/android-StickerView

Reyansh Mishra
  • 1,879
  • 1
  • 14
  • 26
  • Here's a library that does exactly what you need. https://stackoverflow.com/questions/6578320/how-to-apply-zoom-drag-and-rotation-to-an-image-in-android/47861501#47861501 – user2288580 Dec 18 '17 at 02:57