import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.widget.ImageView;
public class ImageLoader {
static LruCache<String, Bitmap> cache;
static {
int maxSize = (int) (Runtime.getRuntime().maxMemory() / 8);
cache = new LruCache<String, Bitmap>(maxSize) {
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
// return value.getByteCount();
}
};
}
public static void loadImage(String url, ImageView image) {
Bitmap bitmap = cache.get(url);
if (bitmap != null) {
image.setImageBitmap(bitmap);
return;
}
new ImageTask(image, cache).execute(url);
}
}
LruCache
最新推荐文章于 2024-09-13 18:54:13 发布