Android Animation details-Frame Animation (Drawable Animation) and androiddrawable
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.
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" > <item android:drawable="@drawable/market_loading_01" android:duration="100"/> <item android:drawable="@drawable/market_loading_02" android:duration="100"/> <item android:drawable="@drawable/market_loading_03" android:duration="100"/> <item android:drawable="@drawable/market_loading_04" android:duration="100"/> <item android:drawable="@drawable/market_loading_05" android:duration="100"/> <item android:drawable="@drawable/market_loading_06" android:duration="100"/> <item android:drawable="@drawable/market_loading_07" android:duration="100"/> <item android:drawable="@drawable/market_loading_08" android:duration="100"/> <item android:drawable="@drawable/market_loading_09" android:duration="100"/> <item android:drawable="@drawable/market_loading_10" android:duration="100"/> <item android:drawable="@drawable/market_loading_11" android:duration="100"/> <item android:drawable="@drawable/market_loading_12" android:duration="100"/></animation-list></span>
The root node of the Frame animation in xml is <animation-list> where oneshot = false is loop playback. If it is true, playing to the last image will stop playing. It 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