替换已弃用的GestureDetector构造函数

4

以下是一个GestureDetector,但整个东西在Eclipse中显示“已弃用的构造函数”。

我使用它来检测快速滑动,它非常有效,但我无法找到一个相应的构造函数。整个东西都已经过时了。我应该转用什么?

无论如何,这是代码:

mGestureDetector = new GestureDetector(
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onDown(MotionEvent e) {
                    return true;
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2,
                        float velocityX, float velocityY) {
                    // Roll the ball in the direction of the fling
                    Direction mCommandedRollDirection = Direction.NONE;

                    if (Math.abs(velocityX) > Math.abs(velocityY)) {
                        if (velocityX < 0)
                            mCommandedRollDirection = Direction.LEFT;


                    else
                                mCommandedRollDirection = Direction.RIGHT;
                        } else {
                            if (velocityY < 0)
                                mCommandedRollDirection = Direction.UP;
                            else
                                mCommandedRollDirection = Direction.DOWN;
                        }

                        if (mCommandedRollDirection != Direction.NONE) {
                            mGameEngine.rollBall(mCommandedRollDirection);
                        }

                        return true;
                    }
                });
        mGestureDetector.setIsLongpressEnabled(false);
    }

显然,我想要相同的功能。

那么,我需要添加哪些新功能(如果有的话),并且我需要使用哪个构造函数?

(是的,我知道Android开发文档,但是像我说的,我很难找到叫做GestureDetector的更新版本)

谢谢!

1个回答

11

以此交换:

GestureDetector gd = new GestureDetector(getActivity(), new OnGestureListener() {
   Methods for the listener 
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接