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

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();回收 

 

相关文章:

  • 2021-04-12
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-25
  • 2021-06-19
  • 2021-08-06
  • 2021-11-10
  • 2021-12-03
  • 2021-08-02
相关资源
相似解决方案