Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ViewPager Lag

Hello I have a viewpager with several pages(using a fragment state pager), and some pngs as backgrounds to those pages. I already followed the Displaying Bitmaps in the Ui (http://developer.android.com/training/displaying-bitmaps/display-bitmap.html) so I am already caching and setting the image drawable in a background thread. But I still get some lag when swithcing pages of the pager. On Each fragment, I only inflate the view on the onCreateView() method, so I have no Idea what may be causing this lag. What can I do to remove this lag/choppy effect?

like image 918
user2235899 Avatar asked Apr 02 '13 11:04

user2235899


2 Answers

You may want to try viewPager.setOffScreenLimit(size) to the number of your pages. This will load all the fragments once and keep from reloading them while swiping.

like image 146
Patrick Avatar answered Oct 18 '22 21:10

Patrick


I had similar problem.

I am showing tutorial-like pages. Each page is a full screen jpg.

At first, I put the pictures in res/drawablesfolder. The viewpager is very laggy when swiping it.

Then I move those jpgs to res/drawable-hdpi folder, the lag is gone.

I think different optimisations are done on the pictures based on folder. So we cannot put everything in res/drawable folder

like image 52
coderek Avatar answered Oct 18 '22 21:10

coderek