onFling 未在 OSX 模拟器上调用?

发布于 2024-11-15 23:45:12 字数 1850 浏览 8 评论 0原文

我正在使用 GestureDetector 并注意到,在 OSX 上的模拟器中运行时,永远不会调用 onFling 方法。

我可以让它在windows下工作,但不能在osx上工作。

我使用了这篇文章中的优秀代码: 网格布局上的 Fling 手势检测

这是代码:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    gestureDetector = new GestureDetector(new MyGestureDetector());

}



public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    gestureDetector.onTouchEvent(event);
    return false;
}

protected void addFlingSupportToView(int view) {
    // TODO Auto-generated method stub

    View v = (View) findViewById(view);
    v.setOnTouchListener(this);

}

class MyGestureDetector extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

                // Log.i("vampidroid", CryptDetails.this.toString());


                finish();

            }
        } catch (Exception e) {
            // nothing

        }
        return false;
    }
}

问题是虽然 OnTouch 被调用,OnFling 事件永远不会被调用!

我在 Windows 上玩了这个代码,它工作正常。当我换成osx并尝试时,它不起作用。

在设备上,代码按预期工作。

你知道这可能是什么吗?只和osx有关吗?

我在网上没有找到任何东西,所以我想这可能只是我自己的,或者没有人检查过。

提前致谢。

I was playing with GestureDetector and notice that the onFling method is never called when running in the emulator on OSX.

I could make it work under windows, but not on osx.

I used the excellent code from this post:
Fling gesture detection on grid layout

This is the code:

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    gestureDetector = new GestureDetector(new MyGestureDetector());

}



public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    gestureDetector.onTouchEvent(event);
    return false;
}

protected void addFlingSupportToView(int view) {
    // TODO Auto-generated method stub

    View v = (View) findViewById(view);
    v.setOnTouchListener(this);

}

class MyGestureDetector extends SimpleOnGestureListener {

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

                // Log.i("vampidroid", CryptDetails.this.toString());


                finish();

            }
        } catch (Exception e) {
            // nothing

        }
        return false;
    }
}

The problem is that although the OnTouch is called, the OnFling event is never called!

I was playing with this code on windows and it was working ok. When I changed to osx and give it a try it didn't work.

On device the code works as expected.

Do you have any idea of what could this be? Is it related only to osx?

I didn't find anything here on in the Net, so I think maybe this is only with me or nobody checked that.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痞味浪人 2024-11-22 23:45:12

我最近遇到了完全相同的问题。不幸的是,幸运的是,我没有从这篇文章中得到任何帮助,但后来幸运地解决了这个问题。答案很简单:不要使用触控板在模拟器中进行“FLING”操作,因为它不起作用。只需插入外部鼠标即可正常工作。

ps 就我而言,我正在使用 macbookpro 进行测试。

编辑:
事实证明,它与内部或外部无关……很抱歉造成混乱。至少对我来说,真正的罪魁祸首是因为我在系统偏好设置中启用了“选项卡单击”,并尝试按两次选项卡进行拖动。默认的“按下点击”可以完美运行,没有任何问题。

I recently came across exactly the same issue. Unfortunately and fortunately, I did not receive any help from this post but resolved the issue sometime later with some luck. The answer is simple: DON'T USE YOUR TRACKPAD TO DO FLING in your emulator because it ain't gonna work. Simply plug in an external mouse and it should work just fine.

p.s. In my case I was testing with a macbookpro.

EDIT:
it turns out it had nothing to do with internal or external.. sorry about the confusion. the real culprit here, at least for me, is because i've enabled "tab to click" in system preferences and tried to tab twice to drag along. The default "press to click" works perfectly without any issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文