# FasterAnimationDrawable **Repository Path**: chenjim/FasterAnimationDrawable ## Basic Information - **Project Name**: FasterAnimationDrawable - **Description**: FasterAnimationDrawable - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2016-08-24 - **Last Updated**: 2022-07-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## AnimationDrawable內存溢出优化 ### 前提介绍 使用AnimationDrawable播放动画一般代码如下,系统会将所有的资源加载到APP, 当**R.drawable.anim**资源较多图片较大,手机配置较低时,会出现OutOfMemoryError ``` imageView.setImageResource(R.drawable.anim); drawableAnim = (AnimationDrawable) imageView.getDrawable(); drawableAnim.stop(); drawableAnim.start(); ``` 下面将介绍一种替换方式,避免出现OutOfMemoryError. ### FasterAnimationsContainer原理 - 详细Android工程源码: https://gitee.com/chenjim/FasterAnimationDrawable - 逐帧decode图片为bitmap,通过[BitmapFactory.Options.inBitmap](https://developer.android.com/reference/android/graphics/BitmapFactory.Options#inBitmap), 复用bitmap减小内存消耗, 参见:[FasterAnimationsContainer.java](https://gitee.com/chenjim/FasterAnimationDrawable/blob/master/app/src/main/java/com/example/fasteranim/FasterAnimationsContainer.java) 效果对比如下 ![效果对比](https://pic.chenjim.com/20200318144644.png?x-oss-process=style/blog) 参考文章 https://github.com/tigerjj/FasterAnimationsContainer