Android swipe conflicts and how to fix them

The first thing to understand is the event distribution mechanism.

 

Regarding the event distribution mechanism, the event distribution of ViewGroup has three key methods, dispatcherTouchEvent, onInterceptTouchEvent, and onTouchEvent.

Distribute, intercept, execute.

 

The main reason for the occurrence of sliding conflicts is that there are multiple nested slidable viewGroups , so if this kind of scene really comes, how should we respond? Which layer of sliding events should be responded to?

Multi-layer nested slidable ViewGroup, three cases (two layers of nesting inside and outside the same sliding direction, two layers of nesting inside and outside the same sliding direction, inner and outer nesting more than 3 layers including 3 layers), it is reasonable to say that if you do not do Any processing, the program should respond to all sliding events by default, but in fact, this default processing method is often not the result we want.

So, how to resolve the swipe conflict?

Method 1) External interception of onInterceptorTouchEvent . People who know the message distribution mechanism should be familiar with this method. It is used to intercept touch events sent from outside to inside. If the return value is true, messages will not be sent down. Make sure that only the outer layer responds to the swipe event, thus resolving the conflict.

Method 2) internal interception of dispathTouchEvent  ,

 

Actual cases, to be filled later.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325709652&siteId=291194637