Android Animation details-Frame Animation (Drawable Animation)
Frame Animation is like a gif image. It uses some static images to achieve the animation effect.
In the Android sdkAnimationDrawableIt is specially designed for Frame Animation. Of course, Frame Animation can also be written in java code or xml, but we recommend that you write it in xml first.
The root node of the Frame animation in xml is the oneshot = false, which indicates loop playback. If it is true, the playback of the last image stops and is called in java.
ImageView imageView;AnimationDrawable animationDrawable;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);imageView = (ImageView) findViewById(R.id.image);imageView.setBackgroundResource(R.drawable.drawable_progress);animationDrawable = (AnimationDrawable) imageView.getBackground();animationDrawable.start();
Because Frame animations are composed of a bunch of static images, they can be used as background.
Written in java code
AnimationDrawable animationDrawable2 = new AnimationDrawable(); Drawable drawable = getResources().getDrawable(R.drawable.fengjing_1); Drawable drawable2 = getResources().getDrawable(R.drawable.fengjing_2); Drawable drawable3 = getResources().getDrawable(R.drawable.fengjing_3); animationDrawable2.addFrame(drawable, 1000); animationDrawable2.addFrame(drawable2, 1000); animationDrawable2.addFrame(drawable3, 1000); animationDrawable2.setOneShot(false); imageView.setBackgroundDrawable(animationDrawable2); animationDrawable2.start();
Well .. That's it. Frame Animation knows that it's almost done.
Project source code