I am trying to rotate a circular image in circle on touch with respect to its center.
I understand that this can be done using the OnTouchListener and onTouch() method .... by using MotionEvent.ACTION_DOWN,MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP events. But I could not find out the angle of rotation .... on touch of different point from the initial postion (ie by taking the initial postion as 0 degree and finding each angle after rotation ...like 0,90.180,270 degrees ...etc ).
Basically My idea is to determine the actually position of the image after rotating the image for certain angle .
Please see the image below :
Please share your idea on this problem .
Any kind of help will be highly appreciated.
Thanks
You need like this:
Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.sheetalkumar105:ZoomImageView-android:1.01'
}
Step 3. Add ZoomImageView in your layout
<com.impulsive.zoomimageview.ZoomImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@drawable/sample"
android:scaleType="matrix"
app:rotation="true"
app:scaledown="true"
/>
app:rotation="true" // Allow to rotate image in view. Default value is true.
app:scaledown="true" // Allow to ZoomOut less than container size. Default value is false.
Full Code:
For rotating image please see this: Android: Rotate image in imageview by an angle
The angle of touch point relatively to your base may be calculated so: arctan((x1 - x0)/(y1 - y0))
where (x0, y0) - the centre of the circle, (x1, y1) - point of touch. Be aware of situation where y1 == y0.
To find the angle of any circle the formula is right ie Math.toDegrees(Math.atan2(x1-x0, y0-y1))
In circle we use little bit trigonometry to calculate angle so we have to take one base which corrds (x0, y0) and other point corrds(x1, y1). Now according to our formula we need to give two parameters ie Base and Parpendicular . So base is x1-x0 and parpendicular is y0-y1 . Please try it I think it will help you!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.