Sdílet prostřednictvím


ViewGroup.OnInterceptTouchEvent(MotionEvent) Method

Definition

Implement this method to intercept all touch screen motion events.

[Android.Runtime.Register("onInterceptTouchEvent", "(Landroid/view/MotionEvent;)Z", "GetOnInterceptTouchEvent_Landroid_view_MotionEvent_Handler")]
public virtual bool OnInterceptTouchEvent (Android.Views.MotionEvent? ev);
[<Android.Runtime.Register("onInterceptTouchEvent", "(Landroid/view/MotionEvent;)Z", "GetOnInterceptTouchEvent_Landroid_view_MotionEvent_Handler")>]
abstract member OnInterceptTouchEvent : Android.Views.MotionEvent -> bool
override this.OnInterceptTouchEvent : Android.Views.MotionEvent -> bool

Parameters

ev
MotionEvent

The motion event being dispatched down the hierarchy.

Returns

Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here.

Attributes

Remarks

Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.

Using this function takes some care, as it has a fairly complicated interaction with View#onTouchEvent(MotionEvent) View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:

<ol> <li> You will receive the down event here. <li> The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal. <li> For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent(). <li> If you return true from here, you will not receive any following events: the target view will receive the same event but with the action MotionEvent#ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here. </ol>

Java documentation for android.view.ViewGroup.onInterceptTouchEvent(android.view.MotionEvent).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to