i need to learn
i need to learn

Reputation: 71

Does onInterceptTouchEvent() really works as the sdk said?

ths sdk said:

3、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().

4、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 ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.

But when i use this method,no matter what onInterceptTouchEvent() returns ,it does the same work! And never did MotionEvent.ACTION_MOVE or MotionEvent.ACTION_UP been captured by this method. Can anybody help me figure it out?

ths!

Upvotes: 7

Views: 3107

Answers (2)

Marcel Wolterbeek
Marcel Wolterbeek

Reputation: 3702

When none of the children of your view return true in onTouchEvent, onInterceptTouchEvent will ONLY be called for MotionEvent.ACTION_DOWN.

Here is a complete description of the MotionEvent processing.

Upvotes: 0

Lukas Hanacek
Lukas Hanacek

Reputation: 1364

Normally the touch goes from most upper view to the lowest through onInterceptTouchEvent and then it goes back via onTouchEvent.

If you return true in onInterceptTouchEvent you forbid it to continue and the view where you returned true is the last one to receive the touch, you consume it

You can also disallow your parent view to consume the event by requestDisallowInterceptTouchEvent(true);

Upvotes: 4

Related Questions