如何检测视图上的双击? [英] How to detect doubletap on a View?

查看:37
本文介绍了如何检测视图上的双击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
Android - 基本手势检测

我正在尝试在 Android 上使用对双击敏感的视图.到目前为止,我学会了设置双击并知道在什么地方处理事件以进行操作:
API:android.view.GestureDetector.OnDoubleTapListener

I'm trying to have a View sensitive to double taps on an Android. So far, I learned to set up the double tap and know what place to handle the event for action:
API: android.view.GestureDetector.OnDoubleTapListener

    private GestureDetector mGestureDetector;
    …
    mGestureDetector = new GestureDetector(this);
    …
    mGestureDetector.setOnDoubleTapListener(new MyDoubleTapListener());
    …
    private class MyDoubleTapListener implements GestureDetector.OnDoubleTapListener {
    public boolean onDoubleTapEvent(MotionEvent e) {                         
                                    return false;                      
    }
                    @Override
                    public boolean onDoubleTap(MotionEvent e) {
                                    // TODO Auto-generated method stub
                                    return false;
                    }

                    @Override
                    public boolean onSingleTapConfirmed(MotionEvent e) {
                                    // TODO Auto-generated method stub
                                    return false;
                    }
}


但是我如何将它链接到视图?这是在一个有几个 View 成员的类中.


But How do I link it to the View? This is in a class that has a few View members.

我真的很感谢你帮我把这些点联系起来!

I'll really appreciate you helping me connect the dots!

推荐答案

您的视图需要实现 onTouchEvent() 方法,并且该方法需要将事件传递给 onTouchEvent() GestureDetector 对象的方法.

Your view needs to implement the onTouchEvent() method, and that method needs to pass the event along to the onTouchEvent() method of the GestureDetector object.

@Override
public boolean onTouchEvent(MotionEvent event) 
{
    Log.v(DEBUG_TAG,"OnTouchEvent !!!");
    boolean result = gestureScanner.onTouchEvent(event);//return the double tap events
    return result;
}

这篇关于如何检测视图上的双击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆