【问题标题】:What is the difference between onDoubleTap listener and onDoubleTapEvent listeneronDoubleTap 监听器和 onDoubleTapEvent 监听器有什么区别
【发布时间】:2017-04-10 18:49:16
【问题描述】:

我是 Android 新手,最近学习了手势!

这两种方法有什么区别?

@Override
public boolean onDoubleTap(MotionEvent e) {
    return false;
}

还有这个

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    return false;
}

他们似乎在做同样的事情。你用的是哪一个,有什么区别

【问题讨论】:

  • 我为一个清晰的想法编辑了答案:) 希望它会有所帮助

标签: java android event-listener


【解决方案1】:

简单的答案是

 boolean onDoubleTap (MotionEvent e) - 

当发生双击时通知。

您可以在发生双击时通知 参数motionEvent 用于第一次点击的向下运动事件。

  boolean onDoubleTapEvent (MotionEvent e)` -

双击手势中的事件发生时通知

您可以在双击手势发生时通知事件,包括downmoveup 事件,并且参数motionEvent 用于运动事件

所以使用doubleTapEvent,您可以在点击时获得额外的标签手势

看看 --> https://stackoverflow.com/a/19629851/5188159 这可能对你的触摸手势有帮助

进一步尝试理解这个例子发生了什么

//initialize the Gesture Detector  
        gd = new GestureDetector(this);  

        //set the on Double tap listener  
        gd.setOnDoubleTapListener(new OnDoubleTapListener()  
        {  
            @Override  
            public boolean onDoubleTap(MotionEvent e)  
            {  
                //set text color to green  
                tvTap.setTextColor(0xff00ff00);  
                //print a confirmation message  
                tvTap.setText("The screen has been double tapped.");  
                return false;  
            }  

            @Override  
            public boolean onDoubleTapEvent(MotionEvent e)  
            {  
                //if the second tap hadn't been released and it's being moved  
                if(e.getAction() == MotionEvent.ACTION_MOVE)  
                {  
                    //set text to blue  
                    tvTapEvent.setTextColor(0xff0000ff);  
                    //print a confirmation message and the position  
                    tvTapEvent.setText("Double tap with movement. Position:\n"  
                            + "X:" + Float.toString(e.getRawX()) +  
                            "\nY: " + Float.toString(e.getRawY()));  
                }  
                else if(e.getAction() == MotionEvent.ACTION_UP)//user released the screen  
                {  
                    tvTapEvent.setText("");  
                }  
                return false;  
            }  

            @Override  
            public boolean onSingleTapConfirmed(MotionEvent e)  
            {  
                //set text color to red  
                tvTap.setTextColor(0xffff0000);  
                //print a confirmation message and the tap position  
                tvTap.setText("Double tap failed. Please try again.");  
                return false;  
            }  
        });

【讨论】:

    猜你喜欢
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 2013-12-24
    • 2014-12-13
    • 2014-02-21
    相关资源
    最近更新 更多