Android ViewPager performance issues when using background

android, android-layout, android-viewpager

Solution

I figured it out myself after some searching, I will leave the answer here for anyone else who encounters this problem.

Apparently android has a lot of trouble rendering a background when the image is stretched. At least on the Galaxy Tab 10.1 running Android 3.2 it does.

The background image I was using was a picture of a wooden floor, because it's a pattern of the same planks repeating itself I managed to crop the image down from 1440 x 1050 to about 350x500. When using this image as background while stretched out over the entire screen there was a huge performance drop. When displaying as a single image in the top left corner however, it worked just fine.

Using the method described here I managed to repeat the image over the entire screen instead of stretching it. Surprisingly enough, I noticed absolutely no extra stress and the transitions went very smooth.

So here it is, hope this will help others out there with the same performance issues!

Problem

I've got an `Activity` made by XML, I've set it's background to a background image I have in my drawable folder. In the same activity I've created a `ViewPager` to allow swiping back and forth between views. All the views inside the `ViewPager` contain one image. Whenever I swipe left or right, the transition is very slow. I tried removing the background image by setting it to white (#fff) and all the lag was gone. It worked perfect! The problem is that I do need that background for the application. Is there any way to optimize a background image or something so swiping will go smoothly again? Currently it's too frustrating to use because of the lag. I also tried cropping the image to a small size and then just stretched it over the screen, but I didn't notice any performance improvements. Also it's not the images fault that are located in the `ViewPager`, when I tested it with TextViews instead there was the same lag.

Original source

Related problems