Manoj
Manoj

Reputation: 2829

How to increase performance of ViewPager?

I want to know how to increase performance of ViewPager. I have ViewPager which has around 25 swipes with large images. I have done memory optimization to avoid OutOfMemoryError. Its working fine.But still there is a lag while swiping. I have set offscreen page limit to 2. If I increase offscreen page limit. It will load more pages in Memory and again I will end up with OOM. So any suggestion how to avoid lag while swiping?

Upvotes: 3

Views: 10802

Answers (3)

ashwin mahajan
ashwin mahajan

Reputation: 1782

Another Possible solution in case of images is that you can try putting them in drawable-hdpi folder, they will load faster. You can look at an answer here.

Upvotes: 0

CoDe
CoDe

Reputation: 11146

You can use FragmentStatePagerAdapter istead using FragmentPagerAdapter.

More detailed explanation given here.

Upvotes: 0

Oleg Vaskevich
Oleg Vaskevich

Reputation: 12672

Your ViewPager cannot cache more than 2 pages? It sounds like you need to tweak your fragments a bit more. For example, make sure you don't stretch the background image, and make sure that your layouts are as simple as possible (i.e. don't use unneeded layouts). If you can see how much memory your app is using for these two pages.

Once you verify that see if you can increase the offscreen page limit. Then check that you are properly destroying the fragments.

Upvotes: 1

Related Questions