I’m looking for a great way to speed up the Gallery view widget in Android Honeycomb. I’m currently using it to display some fairly large images at roughly 340 x 600 pixels, and I’d love for it to be smooth as butter when scrolling through the images.
It’s fairly speedy at the moment, but it doesn’t compare to loading a ScrollView with ImageViews and scrolling through that.
Here’s a simplified version of my getView() method from my custom BaseAdapter:
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = (ImageView) new ImageView(Main.this);
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
((ImageView) convertView).setImageBitmap(createReflection(BitmapFactory.decodeFile(ImageFile, options)));
convertView.setPadding(20, 0, 20, 0);
return convertView;
}
I’ve been experimenting with lazy loading the images, but I didn’t really like the result.
The difference between using a
Galleryand:is that with the
ScrollViewscenario, you are pre-loading all of the images, rather than loading them on the fly as you are in theGalleryscenario.If your number of images is small, and you have enough RAM to support all of them, then just use your
ScrollView.Beyond that, AFAIK there’s not a ton you can do. You can maintain a bitmap cache where you continue decoding a few images ahead of the current ones in the
Galleryand have yourAdapterpull from the cache. However, that will only get you so far — small scrolls will be smooth, but flings past your cache capacity will still result in the decoding being done on demand. That’s pretty much unavoidable.