由于在旧版SDK中,通过TouchEvent.getPointerPosition获取的坐标,在MOVE事件中会偏移,造成计算偏差(API5已修复)。并且VelocityDetector计算速度是基于TouchEvent.getPointerPosition函数的,偏移会造成速度计算错误,比如速度过快、过慢、速度正负值错误等。因此需要使用此类纠正MOVE事件中的偏移。
并且TouchEvent.getPointerPosition函数获取的坐标是相对于偏移位置的:
Obtains the x and y coordinates of a pointer index relative to the offset position during touch control or trajectory tracking in an event.
也就是说,如果该控件通过getPointerPosition获取的坐标在做位移,那么下一次获取的坐标会是加上手指的位移与控件的位移,导致异常。并且VelocityDetector计算速度也会异常。
因此,不建议通过getPointerPosition获取坐标,而使用getPointerScreenPosition来获取。但是如果需要通过VelocityDetector来计算速度,就需要通过TouchEventCompact来纠正getPointerPosition的坐标并与getPointerScreenPosition的坐标同步。
注意:事件分发中的DispatchHelper类中默认使用了TouchEventCompact,并同步了getPointerPosition的坐标与getPointerScreenPosition的坐标。
/**
* 不要反复构造对象
*/
public TouchEventCompact()
touchEventCompact.setAlignToScreenPosition(true);
// 或者使用下面的构造函数:
public TouchEventCompact(boolean alignToScreenPosition)
public void correct(TouchEvent ev)
public float[] getOrigin()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。