【问题标题】:The method getBitmapFromMemCache(String) is undefinedgetBitmapFromMemCache(String) 方法未定义
【发布时间】:2014-05-08 13:34:07
【问题描述】:

我正在学习 http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html 的教程,但我在任何地方都找不到 getBitmapFromMemCache(String) 方法!!

在什么课上可以找到?

【问题讨论】:

    标签: android bitmap


    【解决方案1】:

    这是他们实现的自定义方法。只需查看您链接的页面上的第一个列表:

    private LruCache<String, Bitmap> mMemoryCache;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        // Get max available VM memory, exceeding this amount will throw an
        // OutOfMemory exception. Stored in kilobytes as LruCache takes an
        // int in its constructor.
        final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    
        // Use 1/8th of the available memory for this memory cache.
        final int cacheSize = maxMemory / 8;
    
        mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
            @Override
            protected int sizeOf(String key, Bitmap bitmap) {
                // The cache size will be measured in kilobytes rather than
                // number of items.
                return bitmap.getByteCount() / 1024;
            }
        };
        ...
    }
    
    public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
        if (getBitmapFromMemCache(key) == null) {
            mMemoryCache.put(key, bitmap);
        }
    }
    
    public Bitmap getBitmapFromMemCache(String key) {
        return mMemoryCache.get(key);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-12-11
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 2012-09-19
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多