Android ImageView one finger rotation

I watched a lot of posts, but could not find the answer. I would like to rotate the root image with another small image located on the underside of the root image.

during the rotation of his work, but the first time I click it, it jumps 45 degrees due to 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 advise.

+5
source share
1 answer

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

+3
source

All Articles