替换不推荐使用的GestureDetector构造函数

 佳蓁政睿9 发布于 2023-02-06 06:23

所以下面我有一个GestureDetector,但整个过程在Eclipse中显示"Deprecated Constructor".

我正在使用它来检测flings,它工作得很好,但我找不到并行构造函数.整件事已被弃用.我要切换到什么?

无论如何,这是代码:

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 个回答
  • 交换这个:

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

    2023-02-06 06:50 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有