我想在我的應用程序中顯示facebook新聞源。我得到了urls
的圖像,我試圖通過使用ImageLoader類,MemoryCache類來顯示它們。由於大圖像,我得到OOM Exception
。如何處理Android中的listview中的大型位圖?
我發現在這link使用SoftReference或WeakReference不會處理大的位圖。
爲了解決這個問題,我需要實現不同的類,而不是用過去ImageLoader,MemoryCache,FileCache classes.
我在哪裏可以找到這些類?以及如何實現它們。
import java.lang.ref.SoftReference;
import java.util.HashMap;
import android.graphics.Bitmap;
public class MemoryCache {
private HashMap<String, SoftReference<Bitmap>> cache=new HashMap<String, SoftReference<Bitmap>>();
public Bitmap get(String id){
if(!cache.containsKey(id))
return null;
SoftReference<Bitmap> ref=cache.get(id);
return ref.get();
}
public void put(String id, Bitmap bitmap){
cache.put(id, new SoftReference<Bitmap>(bitmap));
}
public void clear() {
cache.clear();
}
}
請幫助
http://stackoverflow.com/a/12819091/726863 –
可能重複[啓用largeHeap的位圖回收](http://stackoverflow.com/questions/12716574/bitmap-recycle-with-largeheap-enabled) –