Created
October 14, 2014 14:57
-
-
Save easternHong/8d0051c7aadd2b72e9b8 to your computer and use it in GitHub Desktop.
LRU——使用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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