Customized AnimationDrawable which will not load all anim-list frames into memory at once in order to prevent OutOfMemory error
- Frame bitmaps will not be loaded using android build in resource loading mechanism which will scale bitmap according to device dpi. The bitmaps are only "scaled" when drawing.
- Only two bitmaps will be in memory at the same time.
- Frame bitmaps are preloaded off the UI thread.
- Write your anim-list xml as usual
- add dependency
compile 'cn.magictools:FrameByFrameAnimationDrawable:1.0.1'
- Use FrameByFrameAnimationDrawable.loadAnimation(Context context, int resId, boolean extreamlyMemoryLimit) to create a FrameByFrameAnimationDrawable instance.
- Use the instance as normal AnimationDrawable.
- Don't forget to call start() to start the animation.
By default,FrameByFrameAnimationDrawable will cache every frame(only the raw bytes,not bitmap) of the animation-list in memory in order to be I/O efficient when decoding raw bytes into bitmap. However if your app has extreamly memory limit, you can set this parameter to true and the cache will not be used.
Cause we don't use Android build in resource loading mechanism, the bitmaps will not be automatically scaled according to difference dpi.You have to specify the layout_width and layout_height in real dimentions.