Cacheing Drawables on a large ListView of images
If I have a ListView with heaps of images, I obviously can't have all the images stored in memory at once (too large). These images are downloaded from the internet as you move through the list, so removing an image from memory if it leaves the screen and re-downloading when you scroll back is silly lol.
The average image size is approx 40kb about 500 x 500
Should I:
1) When an image is off-screen, compress & decode the image and store it in a database as a byte[], th开发者_StackOverflow中文版en when the user scrolls back to the item, it displays a 'loading' symbol over the image in the UI thread while decoding the image in the background (so as to not lag the scroll), and clear this database on exit or when it gets larger than say 100 images. I'm assuming that decoding an image is relatively quick (less than a second)
or
2) Save this image on the filesystem, and it's location on a database, and fetch the image when the user scrolls to an item, and remove the image from the db and filesystem on exit or when the filesystem gets full (seems like it would take up more room on the phone than option 1). This also seems harder and more annoying to keep the database and the filesystem in 'sync'.
or
3) your suggestion =D
Thanks for your help :)
I strongly recommend using WebImageView, part of the Droidfu library. It handles downloading the images asynchronously (with a placeholder animation while it is doing so) and then also caches the images intelligently for you so you don't have to worry about storing the images.
http://brainflush.wordpress.com/2009/11/23/droid-fu-part-2-webimageview-and-webgalleryadapter/
精彩评论