FasterAnimationsContainer, 没有可以绘制的帧动画

分享于 

2分钟阅读

GitHub

  繁體 雙語
Frame Animation with Drawable without OutOfMemory
  • 源代码名称:FasterAnimationsContainer
  • 源代码网址:http://www.github.com/tigerjj/FasterAnimationsContainer
  • FasterAnimationsContainer源代码文档
  • FasterAnimationsContainer源代码下载
  • Git URL:
    git://www.github.com/tigerjj/FasterAnimationsContainer.git
    Git Clone代码到本地:
    git clone http://www.github.com/tigerjj/FasterAnimationsContainer
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/tigerjj/FasterAnimationsContainer
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    FasterAnimationsContainer

    FasterAnimationsContainer将帮助你避免 OutOfMemoryError。 Android一次加载所有的drawables,因此具有多个帧的动画会导致这里错误。 此类加载&设置,并在后台线程上释放图像。

    易于实现

    
    
    
    
    public class ExampleActivity extends Activity {
    
    
     FasterAnimationsContainer mFasterAnimationsContainer;
    
    
     private static final int[] IMAGE_RESOURCES = { R.drawable.anim_1,
    
    
     R.drawable.anim_2, R.drawable.anim_3, R.drawable.anim_4,
    
    
     R.drawable.anim_5, R.drawable.anim_6, R.drawable.anim_7,
    
    
     R.drawable.anim_8 };
    
    
    
     private static final int ANIMATION_INTERVAL = 500;// 500ms
    
    
    
     @Override
    
    
     protected void onCreate(Bundle savedInstanceState) {
    
    
     super.onCreate(savedInstanceState);
    
    
     setContentView(R.layout.activity_example);
    
    
     ImageView imageView = (ImageView) findViewById(R.id.imageview);
    
    
     mFasterAnimationsContainer = FasterAnimationsContainer
    
    
    . getInstance(imageView);
    
    
     mFasterAnimationsContainer.addAllFrames(IMAGE_RESOURCES,
    
    
     ANIMATION_INTERVAL);
    
    
     mFasterAnimationsContainer.start();
    
    
     }
    
    
    
     @Override
    
    
     protected void onDestroy() {
    
    
     super.onDestroy();
    
    
     mFasterAnimationsContainer.stop();
    
    
     }
    
    
    }
    
    
    
    

      OUT  动画  Drawable