本文介绍了更换德precated GestureDetector构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以下面我有一个GestureDetector,但整个事情显示德precated构造在Eclipse ..

So below I've got a GestureDetector, but the whole thing shows "Deprecated Constructor" in Eclipse..

我用它来检测和飞灰湮灭它的伟大工程,但我无法找到一个并行构造。整个事情是去precated。要什么我切换到?

I'm using it to detect flings and it works great but I'm unable to find a parallel constructor. The whole thing is deprecated. To what do I switch over to?

不管怎么说,这里的code:

Anyways, here's the code:

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);
    }

很显然,我希望同样的功能。
那么什么样的新功能做我要补充(如有)和构造正是我需要使用?

Clearly, I want the same functionality.So what new functions do I have to add (if any) and which constructor exactly do I need to use?

(是的,我知道关于Android开发文档,但就像我说的,我无法找到的新版本what's,它被称为-GestureDetector)

(Yes, I know about the Android dev docs but like I said I'm having trouble finding the newer version of what's-it-called-GestureDetector)

感谢您!

推荐答案

换来这样的:

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

这篇关于更换德precated GestureDetector构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 11:23