Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preload next page in ViewHolder2 like it was automatically done in ViewPager

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

like image 764
Antonis Radz Avatar asked Apr 08 '19 12:04

Antonis Radz


1 Answers

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);
like image 119
AskNilesh Avatar answered Nov 04 '22 08:11

AskNilesh