Android 帧动画

实现

https://www.shanshanstory.com/
在deawable 新建文件 frame_anim.xml



    
    
    
    
    
    
    
    

使用

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame_anim);
        mImageView = (ImageView) findViewById(R.id.iv);
        mImageView.setImageResource(R.drawable.frame_anim);
        AnimationDrawable animationDrawable = (AnimationDrawable) mImageView.getDrawable();
        animationDrawable.setOneShot(false);  //循环
        animationDrawable.start();
    }

Java 代码实现

 private void initAnimationDrawable() {
        AnimationDrawable mAnimationDrawable = new AnimationDrawable();
        for (int i = 0; i < 8; i++) {
            int id = getResources().getIdentifier("d_" + i, "mipmap", getPackageName());
            Drawable drawable = getResources().getDrawable(id);
            mAnimationDrawable.addFrame(drawable, 100);
        }
        mImageView.setImageDrawable(mAnimationDrawable);
        mAnimationDrawable.setOneShot(false);
        mAnimationDrawable.start();
    }

你可能感兴趣的:(Android 帧动画)