Guo
Guo

Reputation: 1803

why can use getParent ().RequestDisallowInterceptTouchEvent (true) disallow Intercepted

@Override   
public boolean dispatchTouchEvent(MotionEvent ev) {  
    // why this code can be executed.
    getParent().requestDisallowInterceptTouchEvent(true); 
    return super.dispatchTouchEvent(ev);   
} 

getParent().requestDisallowInterceptTouchEvent(true) tell parent don't intercept touch event. but if parent already intercept touch event, the event can't pass to child view, and child view how to execute getParent().requestDisallowInterceptTouchEvent(true) ?

Upvotes: 1

Views: 1354

Answers (1)

Anmol
Anmol

Reputation: 8670

I will give you a simple example to why to use.

getParent().requestDisallowInterceptTouchEvent()

If i have a ViewPager and Each page is a ScrollableView(Horizontal Scrolling).Now there is a condition to scroll and changing the page of ViewPager using swipe. i.e View will get confused to scroll or swipe!!!

So this condition need's to be checked in the child View (i.e ScrollableView),once if condition is matched use scrolling and set below

getParent().requestDisallowInterceptTouchEvent(true)

As you don't want any parent View (i.e ViewPager) to interfere in child event.So Basically what the framework will do is won't call onintercepttouchevent() of any of the parent view Reference

But if you want ViewPager to get Event's set below

getParent().requestDisallowInterceptTouchEvent(false)

NOTE: By default on each ACTION_DOWN call of touch Event's requestDisallowInterceptTouchEvent is set to false

Upvotes: 4

Related Questions