A page control layout
-
SmartRefreshLayout
-
CoordinaLayout
-
AppBarLayout
-
RecyclerView
- ViewPager2
-
-
-
Second, the emergence of problems
In the process of sliding up and down, found AppBarLayout addOnOffsetChangedListener callback, resulting in the inside part of the logic is not effective, problems page.
Third, problem analysis
The first reaction is that the slide conflicts, because ViewPager2 handles up and down, left and right slides, and up and down slides, if not handled properly, will result in conflicts between the parent and child slides. Considering that ViewPager2 is actually the use of RecyclerView to achieve the function, and RecyclerView nested transverse sliding RecyclerView is a platial problem, So the priority call RecyclerView setNestedScrollingEnabled to solve.
But when I read the ViewPager2 source code, I didn’t find the corresponding API provided because reflection was used.
The specific code is as follows:
Field field = mViewPager2.getClass().getDeclaredField("mRecyclerView");
field.setAccessible(true);
RecyclerView recyclerView = (RecyclerView) field.get(mViewPager2);
recyclerView.setNestedScrollingEnabled(false);
Copy the code
Perfect solution at last!!