本文共 924 字,大约阅读时间需要 3 分钟。
package zhangphil.cache;import android.graphics.Bitmap;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.util.LruCache;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int CACHE_SIZE = 8 * 1024 * 1024; LruCachemLruCache = new LruCache(CACHE_SIZE); int count = 5; String key; Bitmap bmp; for (int i = 0; i < count; i++) { key = String.valueOf(i); bmp = Bitmap.createBitmap(i + 1, i + 2, Bitmap.Config.ARGB_8888); mLruCache.put(key, bmp); } for (int i = 0; i < count; i++) { key = String.valueOf(i); bmp = mLruCache.get(key); Log.d("key:" + key, "value:" + bmp.getWidth() + "," + bmp.getHeight()); } }}
转载地址:http://bzght.baihongyu.com/