Nestedscrolling parent, nestedscrolling child explain Android — nestedscrolling sliding mechanism

To implement the nestedscrollingparent interface, you need to override the following methods:

Now we probably know something, but what is the logical relationship between these methods?

The whole corresponding process is like this

After the process is clear, let's take a look at the specific meaning of some methods for better understanding.

The first two parameters of this method are used to tell the parent view the distance to scroll this time; The third and fourth parameters are used for the child view to obtain the distance consumed by the parent view and the offset of the parent view position. The consumed parameter is an int array with a length of 2. The first element is the scrolling distance in the X direction consumed by the parent view; The second element is the scrolling distance in the Y direction consumed by the parent view. If these two values are not 0, the child view needs to make some corrections to the scrolling amount. It is precisely because of this parameter that we have a clearer idea when dealing with rolling events and will not be confused by a pile of rolling parameters as before.

This method returns true if the parent consumes part or all of the distance.

The first four parameters are input parameters, which are used to tell the distance that the parent view has consumed and has not consumed. The last parameter is output parameter, which is used for the child view to obtain the offset of the parent view position.

Return value: true if the event was dispatched, false if it could not be dispatched

Here are three examples,

1、 https://github.com/543441727/MyNestedScrolling

2. I adapted the code written by the above person to make it work like pull-down refresh:

https://github.com/huanshen/NestedScrollingParent-Child

3、 https://github.com/qstumn/RefreshLayout

Handle the click event in nestedscrollingchild, and then initiate the scroll request;

Do you want to consume events in the onnestedprescoll of nestedscrollingparent;

Viewgroups with both interfaces need to be processed in both. If the subclass is listview, it can be controlled by intercepting click events. If it is recyclerview, it is not controlled by click events.

Reference article:

Nestedscrollingparent, nestedscrollingchild

Use of nestedscrolling and rolling inertial sliding

Android -- nestedscrolling sliding mechanism

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>