This is the 9th day of my participation in the November Gwen Challenge. See details: The Last Gwen Challenge 2021.

preface

The previous simple handling of the change of the sliding mode, using ListView to achieve similar to the overlay page turning effect, the effect is as follows:

At this time, there are three categories in the project:

Add a few more classes today, introduce the concept of layoutManager, and extract the part above that covers the page-turning effect:

The purpose of introducing LayoutManager

From the ListView analysis, you can see that the part of the ListView that actually displays the content is the SliverList;

The contents of a SliverList change is triggered by the Layout method. So if you want to change the SliverList, you have to change the paint or layout.

So I looked at Android’s LayoutManager and tried to expose the Piant and Layout methods so that I could customize the LayoutManager to directly modify the display content.

Basic rough version of LayoutManager

For the above purposes, start by fully exposing the Paint and Layout methods;

So define an abstract class with two abstract methods paint and Layout:

Then specify the following binding methods to facilitate the use of some of sliver’s own calculation methods:

RenderListView is hosted by layoutManager and bindings are set.

First of all, to develop a basic version of the LayoutManager, will RenderSliverMultiBoxAdaptor paint method right away; So let’s do a basic LayoutManager, so let’s call this one, let’s call it linearLayoutManager;

Now implement the LayoutManager that covers page turning:

The same inheritance overrides, but only the visible parts are dealt with when drawing; Everything else is set to 0 and loops back to front:

RenderSliverList, RenderSliverList, ListView;

And you’re done

conclusion

We now have the overlay flip effect by modifying the Paint method and drawing it to layoutManager;

But is it possible to modify the layout method so that the data source is realistic?

If you change the layoutOffset parameter in the Layout method, it will affect the cache calculation. If you change the layoutOffset parameter, it will affect the cache calculation

Maybe we could change the cache to the index cache in Android?