缩放和平移 ImageView Android
问题描述
我为 ImageView 创建了一个缩放和平移类.
I have created a zoom and pan class for an ImageView.
我正在尝试创建的功能.- 它平移单指触摸和移动- 它可以缩放和平移两根手指的触摸和移动
Features I am trying to create. - It pans on single finger touch and movement - It zooms and pans on two finger touch and movement
在大多数情况下,这非常有效.当我执行以下操作时,它有一个小错误:- 我用一根手指平移(状态:没问题)- 我放下第二根手指,缩放和平移(状态:没问题)- 我松开我的第二根手指(状态:图像有点跳跃)
For the most part this works very well. It has a slight bug when I do the following: - I pan around with one finger (Status: No problem) - I put down a second finger, zoom and pan (Status: No problem) - I release my second finger (Status: The image jumps a little)
希望有人能帮我解决这个问题.
Was hoping someone could help me solve this.
我认为这一定与在case MotionEvent.ACTION_POINTER_UP"中重置 mLastTouchX 和 mLastTouchY 有关
I am thinking that it must have to do with resetting the mLastTouchX and mLastTouchY in "case MotionEvent.ACTION_POINTER_UP"
任何帮助将不胜感激!
推荐答案
似乎 'onDraw' 方法的 'else' 语句中的 canvas.scale() 需要 mLastGestureX 和 mLastGestureY 来停止跳跃.在案例 MotionEvent.ACTION_POINTER_UP"中返回单指平移时,我还会刷新 mLastTouchX 和 mLastTouchY
Seems the canvas.scale() in the 'else' statement of the 'onDraw' method required the mLastGestureX and mLastGestureY to stop the jumping. I also refresh mLastTouchX and mLastTouchY when going back to single finger panning in the 'case MotionEvent.ACTION_POINTER_UP'
这是最终的,可能不适合每个人,因为它不限制平移过去的图像边界,但这应该很容易完成,关于这个主题有很多讨论.
Here's the final, may not suit everyone causes it does not restrict panning past image bounds but that should be easy to accomplish, there are alot of discussions out there on that topic.
这篇关于缩放和平移 ImageView Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!