简体   繁体   English

在Android中检测触摸事件何时结束

[英]Detect when the touch event is over in Android

How can I detect when the touch event is over in Android,in Webviews specifically. 如何在Android(尤其是Webviews)中检测触摸事件何时结束。

pseudocode: if (touch event is over) then do something end 伪代码:如果(触摸事件结束),则结束操作

Thanks! 谢谢!

The MotionEvent object passed to the onTouchEvent(...) method has a getAction() method, you can use it to determine if the event is over. MotionEvent传递给对象onTouchEvent(...)方法具有的getAction()方法,你可以用它来确定该事件是否结束。 eg: 例如:

webViews.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    //pointer down.
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_OUTSIDE:
                    //event has finished, pointer is up or event was canceled or the pointer is outside of the view's bounds
                    break;
            }
            return false;
      }
}

Also, if you want to consume the event (stop it from propagating) just make the onTouch(...) method return true instead of false . 同样,如果您想消耗事件(阻止事件传播),只需使onTouch(...)方法返回true而不是false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM