android回收AnimationDrawable动画的每一帧的图片资源,而释放内存

回收每一帧的图片,释放内存资源

private  void tryRecycleAnimationDrawable(AnimationDrawable animationDrawables) {
		if (animationDrawables != null) {
			animationDrawables.stop();
	        for (int i = 0; i < animationDrawables.getNumberOfFrames(); i++) {
	            Drawable frame = animationDrawables.getFrame(i);
	            if (frame instanceof BitmapDrawable) {
	                ((BitmapDrawable) frame).getBitmap().recycle();
	            }
	            frame.setCallback(null);
	        }
	        animationDrawables.setCallback(null);
	        
	    }
	}

回收完之后可以请求System.gc();回收 

原文地址:https://www.cnblogs.com/mayi168/p/4743062.html