Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preloading the next (or previous) page in ViewPager

Tags:

android

I have managed to show the edges of the next and previous pages by setting a negative page margin. However, the problem is that if I scroll page 1 to the left such that now page 2 is in the center, like so:

0 - [ 1 ] - 2   --->  1 - [ 2 ] - 3

, then page '3' is loaded ONLY after 2 arrives at the center and the swipe ends. This causes a jarring "appear" of page '3' (instead of smoothly sliding in).

How do I have page '3' loaded so that animation is smooth?

like image 534
sparkymat Avatar asked Apr 23 '12 12:04

sparkymat


1 Answers

Have you tried setOffscreenPageLimit() on ViewPager?

like image 95
CommonsWare Avatar answered Nov 17 '22 09:11

CommonsWare