I have a ListView that displays images loaded from the SD (JPGs previously taken with the camera). I use imageView.setImageBitmap()
because the images are too large to display in the list and consume too much (native) memory, so I load a subsampled version with inSampleSize
.
My problem is that the scroll delays before a new row is going to be displayed. Depending on the device the delay is more or less. Once you have reached the end the list the scroll becomes fluid.
Originally I performed the bitmap decoding in the ListAdapter getView():
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inSampleSize = 2; //Subsample the original image
bitmapOptions.inPurgeable = true; //The system can free the ¿native? memory allocated by the bitmap if needed
bitmapOptions.inInputShareable = true; //Works in conjuction with inPurgeable
bitmap = BitmapFactory.decodeFile(path, bitmapOptions);
imageView.setImageBitmap(bitmap);
Then I tried to perform the decoding outside the UI thread. I executed an AsyncTask
to decode all the bitmaps and cache it in memory. So in the getView() I only did imageView.setImageBitmap()
. But I saw the same delay when scrolling. Using the method profiling tool in the DDMS I saw that the method Canvas.native_drawBitmap()
was causing the delay, so the problem was not the bitmap decoding, but the ImageView drawing.
¿Any ideas to workaround this? ¿Why once a row have been displayed the first time there is no more delay when displaying this row? Maybe there is an ImageView displaying cache.