Home » Android » rotate and resize the image view with single finger in android

rotate and resize the image view with single finger in android

Posted by: admin June 15, 2020 Leave a comment


I am developing an app which has feature that resizing and rotating the imageview by dragging its bottom right corner button.

I saw one app which has feature that if we drag the bottom right corner button diagonally imageview size had resized or else if we drag the button left or right side direction imageview had rotated as per direction. I wish to implement this feature in my app

I am struggling to implement single finger rotation as well as resizing the imageview.

Please guide me in right way.enter image description here

I am trying this code, and try to apply zoom and rotate but not able to do please help me.
belove code to do zoom and rotate finger base action.

How to&Answers:

I have Design A Layout that may work as your need.
Download Demo here

Java File

Layout file

and images put in drawable

enter image description here enter image description here enter image description here


please check the repository in github i create it .

count the distance from center point in the rotate and zoom view to the push point.
just use :

and count the OA/OB that value can count the view new height and width

count the angle AOB, the A is the first push point , the B is the last move point ,the O is the center of the View Point .

and then just set new height and width for view ,and count the left and top for view .

souce link : https://github.com/ryanch741/android-view-rotate-zoom-single-finger

the code:


I’m assuming the rotation/scaling happens from the image center? In that case, it’s simple trigonometry to find the rotation angle and the size:

Diagram of triangle formed between picture center and finger

Calculate dx and dy of the finger’s coordinates minus the center coordinates. Math.atan2(dy, dx) is the rotation angle (in radians) and Math.hypot(dx,dy) can be used for the relative size, or just double the dx/dy and use directly.