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);
	}
}

你可能感兴趣的:(cache)