Lazy loading images in ViewPager

1.1k Views Asked by At

So i have 6 categories of pictures and each category has like 150-200 pictures. Each picture has a size of 1MB-10MB. Im not sure how to optimise the loading of the pictures. My ViewPager shows 4 pictures at the same time from 1 category which is selected and can swipe trough all pictures of that category. Could someone lead me in the right direction? Im new to android/programming and everything i have found yet is to complicated.

Thanks.

Edit: I also have a 270MB movie that im not sure how to load so it feels "fast".

2

There are 2 best solutions below

3
Tomislav Novoselec On

First of all, use FragmentStatePagerAdapter for your ViewPager. It will prevent OutOfMemory errors due to the large number of images.

http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html

Second, use Picasso for your image loading, and consider resizing your images down, because you probably don't need full resolution for them to look nice.

https://github.com/square/picasso

And third, if you can let user to choose his favourite video player from the list of installed apps, you should do so.

Android intent for playing video?

4
FuzzyAzu On

I have used this library countless times, it automatically caches the image if the user later returns to the View.

Universial image loader