2013-01-08 26 views
1

我想在我的應用程序中顯示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(); 
    } 
} 

請幫助

+2

http://stackoverflow.com/a/12819091/726863 –

+0

可能重複[啓用largeHeap的位圖回收](http://stackoverflow.com/questions/12716574/bitmap-recycle-with-largeheap-enabled) –

回答

2

看看這個smple項目link

它是指圖像的懶加載

+0

我在我的應用程序中使用了相同的類,但事情是我越來越來自fac的大圖像電子書API,我想顯示它們,因爲這是現在,我得到OOM異常,因爲大位圖。是否有任何方法來顯示大位圖?使用延遲加載後 – user1891910

+0

仍然發生異常? –

+0

我正在使用上面的MemoryCache類,我需要改變它嗎?請找到編輯的文章 – user1891910