Android 手势检测器多点触摸
我正在安卓系统中使用Android 手势检测器多点触摸,android,gesture,multi-touch,Android,Gesture,Multi Touch,我正在安卓系统中使用OnGetureListener界面和GestureDetector使用触摸手势 我制作了一个应用程序来测试检测两个手指是否有效,在onFlp(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY)中,我打印了不同MotionEvents的id,但这些id是相同的(显然只检测一个手指) GestureDetector是否支持多点触控事件?问题 默认情况下,使用OnGestureListener检测多点触控手
OnGetureListener
界面和GestureDetector
使用触摸手势
我制作了一个应用程序来测试检测两个手指是否有效,在onFlp(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY)
中,我打印了不同MotionEvents
的id,但这些id是相同的(显然只检测一个手指)
GestureDetector
是否支持多点触控事件?问题
默认情况下,使用OnGestureListener
检测多点触控手势似乎没有实现
您可能尝试的第一件事是读取event.pointerCount
以获取屏幕上的手指数。但是,这将等于1
。这是因为你将(很可能)永远无法用两个手指在完全相同的毫秒内触摸屏幕
修复它 您必须缓冲
指针计数
(屏幕上的手指数量)。首先将这些变量添加到要跟踪手势的上下文中的某个位置:
// track how many fingers are used
var bufferedPointerCount = 1
var bufferTolerance = 500 // in ms
var pointerBufferTimer = Timer()
然后,在onTouchEvent(事件:MotionEvent)
函数中,添加以下内容:
// Buffer / Debounce the pointer count
if (event.pointerCount > bufferedPointerCount) {
bufferedPointerCount = event.pointerCount
pointerBufferTimer = fixedRateTimer("pointerBufferTimer", true, bufferTolerance, 1000) {
bufferedPointerCount = 1
this.cancel() // a non-recurring timer
}
}
基本上,这会跟踪显示器上手指的最大数量,并使其在bufferTolerance
毫秒(此处:500)内保持有效
我目前正在我创建的自定义Android启动器中实现它(|请参阅)手机支持多点触控吗?是的,但我无法使用此界面管理多个手指。