Custom ListView with many images gets Out Of Memory Exception

☆樱花仙子☆ 提交于 2019-12-05 13:05:03
Devunwired

Don't load them all into memory at once, only load the images you need to display into Bitmap objects; and make sure the images you load are only the size you need to display (don't fully load a 1900x1200 image to show a 300x200 thumbnail). Your application's heap size is ~30MB (device dependent, but that's a good rule of thumb), and a Bitmap will take up Width*Height*4 bytes in memory once loaded.

One method is to cache the images onto disk as they are downloaded so they don't have to be in memory, and always check the cache for an image before downloading it. You can also use the cache to load up a handful of images into memory that need to be displayed in the list at that time.

You can also make use of the BitmapFactory.Options.inSampleSize options to reduce the size of an image while it is loaded, rather than loading in the entire image and then creating a small copy, which wastes time and memory.

HTH

Take a look at : http://developer.android.com/training/displaying-bitmaps/index.html for help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!