[英]How to rotate an image in circular manner with respect to its center on touch in android
我試圖在觸摸時圍繞其中心旋轉圓形圖像。
我知道這可以使用OnTouchListener 和 onTouch() 方法來完成......通過使用MotionEvent.ACTION_DOWN , MotionEvent.ACTION_MOVE 和 MotionEvent.ACTION_UP事件。 但是我無法從初始位置(即,將初始位置設為 0 度並在旋轉后找到每個角度...如 0,90.180,270 度)時找出旋轉的角度....。 ..等等 )。
基本上我的想法是在將圖像旋轉一定角度后確定圖像的實際位置。
請看下圖:
請分享您對這個問題的想法。
任何形式的幫助將不勝感激。
謝謝
你需要這樣:
步驟 1. 將 JitPack 存儲庫添加到您的構建文件中將其添加到存儲庫末尾的根 build.gradle 中:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
步驟 2. 添加依賴項
dependencies {
implementation 'com.github.sheetalkumar105:ZoomImageView-android:1.01'
}
步驟 3. 在您的布局中添加 ZoomImageView
<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.
完整代碼:
有關旋轉圖像,請參閱: Android:按角度旋轉圖像視圖中的圖像
接觸點相對於您的底座的角度可以這樣計算: arctan((x1 - x0)/(y1 - y0))
其中 (x0, y0) - 圓心,(x1, y1) - 接觸點. 注意 y1 == y0 的情況。
要找到任何圓的角度,公式是正確的,即Math.toDegrees(Math.atan2(x1-x0, y0-y1))
在圓中,我們使用一點三角函數來計算角度,因此我們必須取一個與 (x0, y0) 相關的底和其他點與 (x1, y1) 相關。 現在根據我們的公式,我們需要給出兩個參數,即Base和Parpendicular 。 所以base是x1-x0 , parpendicular是y0-y1 。 請嘗試一下,我認為它會對您有所幫助!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.