GridView with many images leads to slow / rough scrolling

In my application, I have a GridView with many images (~ 100), a layout similar to this:

I am testing my application on HTC Desire HD. When I have 88 images in gridview, the scroll is smooth. Now, if I add 10 images, so that I have only 98, there is no more smooth scrolling - now it is β€œslower”, more coarse, it looks like scrolling in large pieces.

This gridview is present in TabLayout, in which I also have a ListView with many elements. When using 98 images in a gridview, the scroll in this list also affects. Thus, he, like the whole application, is becoming slower (or uses more β€œpower” than the phone can control).

Is there any way to optimize the gridview so that it does not use so much energy?

(PS: when using about 150 images, the application simply stops working (it turns off, and no error is displayed in the / debug log).

+4
source share
4 answers

In the end, I went with the solution provided by NOSTRA:

Lazy loading images in a ListView

It works very well.

+2
source

Make sure you recycle your images in the getView () method of the adapter. Something like that:

public View getView(int position, View convertView, ViewGroup parent) { // if it not recycled, initialize some attributes if (convertView == null) { convertView = new View(...); } ... 

instead of creating new views every time getView () is called.

+4
source

I do not code on Android, but I would suggest a lazy approach to visibility. All your images look the same size, so handle the scroll event and show only the images that can be seen on the current truncation screen (screen), while hiding the rest.

I assume that Android uses its processing power on images that cannot be seen while scrolling, which causes fluctuations.

+1
source

First, do not save all your bitmaps in private Bitmap[] mBitmap; . This is likely to cause your application to crash. Read them from the file system using BitmapFactory .

Secondly, you should not scale images in your adapter, which is expensive:

 imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 

Try a set of images that you don't need to scale.

0
source

All Articles