Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android ImageView one finger rotation

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.

like image 915
joseRo Avatar asked May 02 '17 19:05

joseRo


1 Answers

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

like image 141
Reyansh Mishra Avatar answered Nov 07 '22 14:11

Reyansh Mishra