Reputation: 470
I am currently using a ViewPager
with a FragmentStatePager
adapter, with approx 25 different fragments (and different relativelayouts
). When I scroll I generally notice substantial lag when swiping to some views, except when I declare viewpager.setoffscreenpagelimit(25)
. Is there a way to increase performance of this viewpager
, without having all the pages loaded at all time?
Upvotes: 2
Views: 7633
Reputation: 5469
Can you please add more detail to your question? For example, what are you doing in each pages?
Have you updated to latest Android Support Library?
Changes for v4 support library:
You have always to remember that FragmentStatePagerAdapter auto-save pages and remove them when not used. So if you swipe very fast there will be a lot of load/unload of pages. You can try to increase the amount of pages loaded in memory.
Upvotes: 1
Reputation: 1784
Using the ViewPager out of the box will load a maximum of three Fragments/Views. Stay with that number. It is not the ViewPager that is slow, you are doing something in your code that makes it slow. Does any of your Fragment do any blocking or CPU-consuming task? For instance loading Bitmaps? Are you having some parsing that could be done in an AsyncTask? Maybe you could put such things else where and save it to a database and then when you load the Frament it will stay very clean and efficient if reading from a database.
Upvotes: 3