private void displayImg(ImageView imageView, String url) { RequestQueue mQueue = Volley.newRequestQueue(context); ImageLoader imageLoader = new ImageLoader(mQueue, new BitmapCache()); ImageLoader.ImageListener listener = ImageLoader.getImageListener(imageView, R.mipmap.ic_launcher, R.mipmap.ic_launcher); imageLoader.get(url, listener); //指定图片允许的最大宽度和高度 // imageLoader.get("http://developer.android.com/images/home/aw_dac.png",listener, 200, 200); } public class BitmapCache implements ImageLoader.ImageCache { private LruCache<String, Bitmap> cache; public BitmapCache() { cache = new LruCache<String, Bitmap>(10 * 1024 * 1024) { @Override protected int sizeOf(String key, Bitmap bitmap) { return bitmap.getRowBytes() * bitmap.getHeight(); } }; } @Override public Bitmap getBitmap(String url) { return cache.get(url); } @Override public void putBitmap(String url, Bitmap bitmap) { cache.put(url, bitmap); } }
本文出自 “移动平台开发” 博客,请务必保留此出处http://liuxudong1001.blog.51cto.com/10877072/1789445
原文地址:http://liuxudong1001.blog.51cto.com/10877072/1789445