如何在Android中触摸相对于其中心的圆形方式旋转图像

问题描述 投票:2回答:3

我试图在圆形图像上旋转相对于其中心的圆形图像。

我知道这可以使用OnTouchListener和onTouch()方法来完成....使用MotionEvent.ACTION_DOWN,MotionEvent.ACTION_MOVE和MotionEvent.ACTION_UP事件。但是我无法找到旋转角度......从初始位置触摸不同点(即将初始位置设为0度并在旋转后找到每个角度...如0,90.180,270度。 ..etc)。

基本上我的想法是在将图像旋转一定角度后确定图像的实际位置。

请看下面的图片:

请分享您对此问题的看法。

任何形式的帮助将受到高度赞赏。

谢谢

android geometry ontouchlistener image-rotation
3个回答
2
投票

你需要这样的:

enter image description here

步骤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. 

Zoom or Rotate image on pinch or touch in Android ImageView

完整代码:

https://github.com/sheetalkumar105/ZoomImageView-android/blob/master/zoomimageview/src/main/java/com/impulsive/zoomimageview/ZoomImageView.java


0
投票

有关旋转图像,请参阅:Android: Rotate image in imageview by an angle

可以如下计算触摸点相对于基点的角度:arctan((x1 - x0)/(y1 - y0))其中(x0,y0) - 圆的中心,(x1,y1) - 触摸点。请注意y1 == y0的情况。


-1
投票

要找到任何圆的角度,公式是正确的,即Math.toDegrees(Math.atan2(x1-x0,y0-y1))

在圆圈中,我们使用一点三角法来计算角度,因此我们必须采用一个基础来修正(x0,y0)和其他点corrds(x1,y1)。现在根据我们的公式,我们需要给出两个参数,即Base和Parpendicular。所以base是x1-x0,而parpet是y0-y1。请试一试,我认为它会对你有所帮助!!

© www.soinside.com 2019 - 2024. All rights reserved.