2

The problem is ive got sort of book reader, landscape shows two pages and portrait just one. For some reason I blocked destroying activities on config change. the story is pretty much the same like here ViewPager + FragmentStatePagerAdapter + orientation change. Although the question is bit different - Id wish to store not 3 but 5 fragments. its about rendering time, Im easily handling swipe stuffs with adding +-1 in portrait and +-2 in landscape, though the problem is, in landscape orientation, it wont render proper next / previous fragments. As obviously its rendering +1 and -1 items, I want +2/-2 items to be instantiated instead. So theres either some kind of solution that changes positions to instantiate in landscape (which im not aware of though), or storing 5 items in an adapter instead of just 3. Anyone with any sort of proper solution?

Community
  • 1
  • 1
Maciej Boguta
  • 1,354
  • 1
  • 12
  • 15

2 Answers2

12

You can store 5 items in the adapter by setting the OffscreenPageLimit of the ViewPager to 4:

viewPager.setOffscreenPageLimit(4);

hope that I've helped you.

Nabz
  • 390
  • 2
  • 14
2

try this: mViewPager.setOffscreenPageLimit(4);

Abhishek Shukla
  • 1,242
  • 8
  • 11