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

1 Answers

1
Nilesh Rathod On Best Solutions

Now it is possible in ViewPager2

Use Version 1.0.0-alpha04

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 and restoreState methods made final in FragmentStateAdapter
  • ViewPager2.Orientation and ViewPager2.ScrollState annotations made non-public

SAMPLE CODE

viewPager2.setOffscreenPageLimit(2);