作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的应用程序中显示 facebook Newsfeed。我得到了图像的 urls
,并尝试使用 ImageLoader 类、MemoryCache 类 来显示它们。由于图像较大,我收到 OOM 异常
。
我在这个 link 中找到使用 SoftReference 或 WeakReference 将无法处理大位图。
为了处理这个问题,我需要实现不同的类,而不是使用过去的 ImageLoader,MemoryCache,FileCache 类。
我在哪里可以找到这些类?以及如何实现它们。
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();
}
}
请帮忙
最佳答案
看看这个简单的项目 link
图片延迟加载
关于android - 如何在 android 的 ListView 中处理大位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14209962/
我是一名优秀的程序员,十分优秀!