Skip to content

Instantly share code, notes, and snippets.

@duanhong169
Created March 26, 2013 08:37
Show Gist options
  • Save duanhong169/5243929 to your computer and use it in GitHub Desktop.
Save duanhong169/5243929 to your computer and use it in GitHub Desktop.
private LruCache<String, BitmapDrawable> mMemoryCache;
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
// 使用最大可使用内存的1/8作为缓存
final int cacheSize = maxMemory / 8;
mMemoryCache = new LruCache<String, BitmapDrawable>(cacheSize) {
/**
* 衡量某个bitmap大小的方法
*/
@Override
protected int sizeOf(String key, BitmapDrawable value) {
final int bitmapSize = getBitmapSize(value) / 1024;
return bitmapSize == 0 ? 1 : bitmapSize;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment