2016-07-25 39 views
0

我有一個活動,在這個活動中我做了一個動畫。 但是有一個內存泄漏,然後我使用LruCache。Android LruCache和Animationdrawable

我的問題是如何在我的動畫中設置來自LruCache的圖像?

+0

請添加詳細信息到你的問題,也很難幫助你現在這樣的信息很少。 –

回答

0

LruCache:

private LruCache<Integer, Bitmap> mBitmapCache; 

public final static Integer[] resIdList = new Integer[] { 
     R.drawable.image0, R.drawable.image1, R.drawable.image2, 
     R.drawable.image3, R.drawable.image4, R.drawable.image5, 
     R.drawable.image6, R.drawable.image7, R.drawable.image8, 
     R.drawable.image10}; 


private void initializeCache() { 

    final int memClass = ((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); 

    mCache = new LruCache<Integer, Bitmap>(1024 * 1024 * (memClass/4)) { 

     @SuppressLint("NewApi") 
     protected int sizeOf(String key, Bitmap value) { 
      return value.getByteCount(); 
     } 
    }; 

    int imgId = 0; 

    for (int i = 0; i < resIdList.length; i++) { 
     imgId = resIdList[i]; 
     Bitmap bitmap = BitmapFactory.decodeResource(getResources(), pingImgResId); 
     mBitmapCache.put(pingImgResId, bitmap); 
    } 
+0

img.setBackgroundResource(R.drawable.animation); AnimationDrawable frameAnimation =(AnimationDrawable)img.getBackground(); frameAnimation.start(); –

+0

我如何獲得動畫圖像? –

+1

這是你的答案還是你的問題? –