Android studio 未调用Android studio OnFling事件

Android studio 未调用Android studio OnFling事件,android-studio,gesture,Android Studio,Gesture,我正试图将滑动控制添加到我的应用程序中。该应用程序是全屏和横向模式。我想检测在一个只有画布的活动中的滑动。我试着自己做,但没有成功。我看了一本教程,但这本书很管用。它正在调用其他函数,但onFling不起作用。这是我的手势听众 public class GestureListener extends GestureDetector.SimpleOnGestureListener { private static final int SWIPE_THRESHOLD = 100; private

我正试图将滑动控制添加到我的应用程序中。该应用程序是全屏和横向模式。我想检测在一个只有画布的活动中的滑动。我试着自己做,但没有成功。我看了一本教程,但这本书很管用。它正在调用其他函数,但onFling不起作用。这是我的手势听众

public class GestureListener extends GestureDetector.SimpleOnGestureListener {

private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@Override
public boolean onDown(MotionEvent e) {
    return true;
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    boolean result = false;
    try {
        float diffY = e2.getY() - e1.getY();
        float diffX = e2.getX() - e1.getX();
        if (Math.abs(diffX) > Math.abs(diffY)) {
            if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                if (diffX > 0) {
                    onSwipeRight();
                } else {
                    onSwipeLeft();
                }
                result = true;
            }
        }
        else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
            if (diffY > 0) {
                onSwipeBottom();
            } else {
                onSwipeTop();
            }
            result = true;
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return result;
}

public void onSwipeRight() {
}

public void onSwipeLeft() {
}

public void onSwipeTop() {
}

public void onSwipeBottom() {
}
}

那是我的活动

` 私人手势检测器

public Game(Context context) {
    super(context);

    SurfaceHolder surfaceHolder = getHolder();
    surfaceHolder.addCallback(this);

    gameLoop = new Loop(this, surfaceHolder);

    GestureListener gestureListener = new GestureListener();

    mDetector = new GestureDetector(context, gestureListener);

    setFocusable(true);
}

@Override
public boolean onTouchEvent(MotionEvent event) {

    mDetector.onTouchEvent(event);

    return super.onTouchEvent(event);
}
`