Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of onInterceptTouchEvent, onTouchEvent and onTouch in android Development

Shulou Source: shulou.com Published: 2022-06-02 04:44:39 09月10日 Update

This article mainly shows you the "android development of onInterceptTouchEvent, onTouchEvent and onTouch example analysis", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "android development onInterceptTouchEvent, onTouchEvent and onTouch sample analysis" this article.

1. OnTouch

OnTouch is a method in the OnTouchListener interface of View that handles events in which View and its subclasses are handled by touch. Of course, the premise is that the touch time can be passed to the specified view. Q1: why can't it be delivered?

/ * * Interface definition for a callback to be invoked when a touch event is * dispatched to this view. The callback will be invoked before the touch * event is given to the view. * / public interface OnTouchListener {/ * * Called when a touch event is dispatched to a view. This allows listeners to * get a chance to respond before the target view. * * @ param v The view the touch event has been dispatched to. * @ param event The MotionEvent object containing full information about * the event. * @ return True if the listener has consumed the event, false otherwise. * / boolean onTouch (View v, MotionEvent event);}

II. OnTouchEvent

OnTouchEvent is also a method defined in view. Handles gesture events passed to view. The types of gesture events include four types of ACTION_DOWN,ACTION_MOVE,ACTION_UP,ACTION_ call events.

/ * Implement this method to handle touch screen motion events. * * @ param event The motion event. * @ return True if the event was handled, false otherwise. * / public boolean onTouchEvent (MotionEvent event) {. …… }

Once the onTouchEvent method is called and returns true, the gesture event ends and is not passed down to the child control. When will Q2:onTouchEvent be called?

III. OnInterceptTouchEvent

OnInterceptTouchEvent is defined in ViewGroup. The layout layout class in Android generally inherits this class. OnInterceptTouchEvent is used to intercept gesture events, and each gesture event calls onInterceptTouchEvent first.

Public boolean onInterceptTouchEvent (MotionEvent ev) {return false;}

If this method returns false, the gesture event is passed to the child control; if true is returned, the onTouchEvent method is called.

These are all the contents of the article "sample Analysis of onInterceptTouchEvent, onTouchEvent and onTouch in android Development". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Events gestures methods examples analysis development content articles processing controls is in learning help premise layout interface time time easy to understand yes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Technology vpn Huawei Docker