ほとんどすべてのジェスチャーを消費する必要がある View を作成しています。これを行うために、ScaleGestureDetector と GestureDetector を作成しました。また、リスナー クラスを 1 つ作成し、必要なすべてのインターフェイスを実装できることに気付きました。だから私はしました。OnGestureListener と OnDoubleTapListener は同じクラスに由来するため、これは完全に理にかなっていますが、次のようになります。
- ScaleGestureDetector は独自のリスナー クラスを期待しますか?
- 同じクラスに満足している場合、独自のオブジェクトを期待しますか?
- 逆に、両方の検出器で同じリスナーを使用する必要がありますか?
実験により、次のことが確認されました。
- 確かに 1 つのリスナー クラスを使用できますが、
- ScaleGestureDetector と GestureDetector は、同じイベントを消費すると、お互いに迷惑をかける可能性があります。でも
通常の検出器を実行する前に、常にスケール検出器を最初に呼び出してから、その isInProgress() メソッドをチェックすることで、この相互のイライラを防ぐことができるようです。
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; }