使用setScaleX()时,为什么motionEvent.getX()返回不一致的值? [英] Why motionEvent.getX() return inconsistent values, when using setScaleX()?

查看:98
本文介绍了使用setScaleX()时,为什么motionEvent.getX()返回不一致的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的子视图位于一个ViewGroup中.我想用捏来缩放(缩放)孩子.我正在使用setScaleX/Y()缩放子级.比例是从OnTouch()中2个指针之间的距离计算得出的.但是,当我设置子项的比例时,它会使motionEvent.getX()不一致,从而使比例不一致:

  MotionEvent.ACTION_MOVE:p1.set(ev.getX(firstPointerIndex),v.getY(firstPointerIndex));Log.d(TAG,"Touch xy:" + ev.getX(firstPointerIndex)+," + ev.getY(firstPointerIndex));this.setScaleX(scale);this.setScaleY(scale);休息; 

输出

这是一个指针的输出:

  12-09 11:55:14.828:D/IconItem(14408):触摸xy:54.622437,135.7986512-09 11:55:14.843:D/IconItem(14408):触摸xy:35.761047,192.0736112-09 11:55:14.863:D/IconItem(14408):触摸xy:54.669342,135.6586912-09 11:55:14.878:D/IconItem(14408):触摸xy:35.85121,191.804612-09 11:55:14.898:D/IconItem(14408):触摸xy:54.715958,135.5195912-09 11:55:14.898:D/IconItem(14408):触摸xy:35.94078,191.5373512-09 11:55:14.913:D/IconItem(14408):触摸xy:54.776947,135.33765 

问题

问题是x坐标跳35-54或y坐标跳135-191.我不明白这些跳跃来自何处.当我不使用setScaleX/Y()时,ev.getX/T()是一致的-没有跳转.谁能点燃我?我不应该使用这些比例尺方法吗?它们会影响ev.getX/Y()吗?如何以其他方式实现视图的缩放(带捏)?

解决方案

是的,每个运动事件都在视图的坐标中给出,并考虑了视图的矩阵(矩阵又包括比例尺).您可以尝试通过 canvas.scale()进行缩放,而不是像

Output

This is the output of one pointer:

12-09 11:55:14.828: D/IconItem(14408): Touch xy:54.622437, 135.79865
12-09 11:55:14.843: D/IconItem(14408): Touch xy:35.761047, 192.07361
12-09 11:55:14.863: D/IconItem(14408): Touch xy:54.669342, 135.65869
12-09 11:55:14.878: D/IconItem(14408): Touch xy:35.85121, 191.8046
12-09 11:55:14.898: D/IconItem(14408): Touch xy:54.715958, 135.51959
12-09 11:55:14.898: D/IconItem(14408): Touch xy:35.94078, 191.53735
12-09 11:55:14.913: D/IconItem(14408): Touch xy:54.776947, 135.33765

Question

The problem is the jumps 35-54 at x-coord or 135-191 at y-coord. I can't understand where these jumps are coming from. When I don't use setScaleX/Y(), the ev.getX/T() are consistent - no jumps. Could anyone light me? Shouldn't I use these scale methods? Does they affect the ev.getX/Y()? How can I implement the zoom(with pinch) of the view in other way?

解决方案

Yes, each motion event is given in the view's coordinates, taking into account the view's matrix (which in turn includes the scale). You could try to do your scaling via canvas.scale() instead of scaling the View, as in Making Sense of Multitouch, or possibly by catching the MotionEvents in another view that is not undergoing the scale operation.

这篇关于使用setScaleX()时,为什么motionEvent.getX()返回不一致的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆