1. Step-by-step animation (frame Animation)
You typically define an XML template file that frames-by-frame animations under the res/drawable/directory of an Android project. When encoding, you need to put in the animation template file <animation-list> tags in order to place the picture you want to play, and set the time between playback.
<animation-listxmlns:android= "Http://schemas.android.com/apk/res/android" android:oneshot= "false" >< Item android:drawable= "@drawable/a001" android:duration= "/><item android:drawable=" @drawable/a002 " android:duration= "/><item android:drawable=" @drawable/a003 "android:duration=" (omitted)/><!-- ></animation-list>
Note: frames-per-frame animations cannot be used independently, and the animation effect is displayed with the help of the ImageView image control.
Example: (The ID of the ImageView element is M_image_view, and the animation template file above is named M_frame_animation)
public class Mainactivity extends Activity {animationdrawable manimationdrawable; @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); ImageView MImageView = (ImageView) Findviewbyid (R.id.m_image_view); Mimageview.setbackgroundresource (r.drawable.m_frame_animation); manimationdrawable = Mimageview.getbackground (); Manimationdrawable.start ();} @Overridepublic void OnPause () {super.onpause (); Manimationdrawable.stop ();}}
2. Motion Tween (Tween Animation)
Frames-by-frame animation simulates the effect of an animation by continuously playing a picture, while a tweened animation is achieved by adding a simple animation effect between two keyframes.
There are 5 types of tweened animations supported by the Android app framework. Specifically implemented in the Android.view.animation class library.
+alphaanimation: Transparency (Alpha) gradient effect, corresponding to <alpha/> label.
+translateanimation: Displacement gradient, you need to specify the starting and ending coordinates of the move point, corresponding to the <translate/> tag.
+scaleanimation: Zoom gradient, you can specify a reference point for scaling, corresponding to the <scale/> label.
+rotateanimation: Rotates the gradient, specifying the reference point for the rotation, corresponding to the <rotate/> label.
+animationset: A combination of gradients that supports the combination of various gradient effects, corresponding to <set/> tags. The effects of
motion tweens can also be defined using the XML language, which is typically placed in the res/anim/directory of the Android project.
<set xmlns:android= "http://schemas.android.com/apk/res/android" android:interpolator= "@android: anim/ Decelerate_interpolator "><!--in 1000ms (1 seconds) time, from transparency 0 (fully transparent) to 1 (opaque), while the center of the element from the size of 0.1 (One-tenth) into 1 (normal)-->< Alphaandroid:fromalpha= "0.0" android:toalpha= "1.0" android:duration= "$"/><scaleandroid:fromxscale= "0.1" Android:toxscale= "1.0" android:fromyscale= "0.1" android:toyscale= "1.0" android:duration= "50%" android:pivotx= " "Android:pivoty=" 50% "android:startoffset="/></set>
Example: (The ID of the ImageView element is M_image_view, and the animation template file above is named M_tween_animation)
public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); ImageView Mimageview = (ImageView) Findviewbyid (R.id.m_image_ view); Animation manimation = Animationutils.loadanimation (this, r.drawable.m_tween_animation); Mimageview.startanimation ( manimation);}}
Animate one-frame and tweened animations