我正在创建一个视图,需要消耗几乎任何手势。为此,我创建了一个ScaleGestureDetector和一个GestureDetector。我还创建了一个监听器类,并意识到可以实现我需要的每个接口;所以我做了。这使得总的意义OnGestureListener和OnDoubleTapListener,因为它们来自同一类,但:一个OnGestureListener对象可以处理两个GestureDetector对象吗?
- 请问ScaleGestureDetector想到自己的监听器类?
- 如果它对同一个班级感到满意,它会期待它自己的对象吗?
- 相反,我是否需要在两个探测器上使用相同的监听器?
实验已经确认以下内容:
- 你的确可以使用一个监听器类,但如果他们消耗相同的事件
- ScaleGestureDetector和GestureDetector可惹恼对方。然而
看来你可以总是先打电话规模探测器,然后运行常规检测前检查其isInProgress()方法阻止这种相互irking:
public boolean onTouchEvent(MotionEvent event) { //let the ScaleGestureDetector try first mScaleDetector.onTouchEvent(event); //if isInProgress() returns true then it's consuming the event if(mScaleDetector.isInProgress()) return true; //if isInProgress() returns false it isn't consuming the event //it's therefore safe to pass it to the regular detector mPrimaryDetector.onTouchEvent(event); return true; }
这非常有用,谢谢!我根本不知道“ignoreMultiTouch”。 –
顺便说一句,“烦恼”的表现形式是“MotionEvent”被一个监听器类改变,导致另一个监听器崩溃。 –
@Noel看起来像ignoreMultiTouch参数已被重命名为未使用,并像它被命名不再使用。不知道为什么。 – Flynn81