How to preload next page and page before in ViewPager2? My app uses list from api in each ViewPager2 tab screen. It is good user experience when next page is loaded before user swipes to it. On old ViewPager it was done automatically
Asked
Active
Viewed 3,948 times
1 Answers
25
Now it is possible in ViewPager2
New features
- offscreenPageLimit: allows for a tight control of the number of page Views / Fragments kept in the view hierarchy
API changes
- orientation and
isUserScrollable
attributes are no longer part of SavedState saveState
andrestoreState
methods made final in FragmentStateAdapterViewPager2.Orientation
andViewPager2.ScrollState
annotations made non-public
SAMPLE CODE
viewPager2.setOffscreenPageLimit(2);