Skip to content

Instantly share code, notes, and snippets.

@easternHong
Created October 14, 2014 14:57
Show Gist options
  • Save easternHong/8d0051c7aadd2b72e9b8 to your computer and use it in GitHub Desktop.
Save easternHong/8d0051c7aadd2b72e9b8 to your computer and use it in GitHub Desktop.
LRU——使用
private final BitmapCache mMemoryCache;
//一般在构造函数实现
mMemoryCache = new BitmapCache();
private Bitmap getBitmapFromMemCache(final int key) {
return mMemoryCache.get(key);
}
private void addBitmapToMemoryCache(final int key, final Bitmap bitmap) {
if (getBitmapFromMemCache(key) == null) {
mMemoryCache.put(key, bitmap);
}
}
//这是在getview里面实现
Bitmap bitmap = getBitmapFromMemCache(pos);
if (bitmap == null) {
Drawable d = appList.get(pos).appIcon;
bitmap = ((BitmapDrawable) d).getBitmap();
addBitmapToMemoryCache(pos, bitmap);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment