`
huiji232
  • 浏览: 11585 次
社区版块
存档分类
最新评论

LruCache

 
阅读更多
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);
	}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics