1 Frames-per-frame animation Step-by-frame animation is a sequence of pictures that show in a certain order. Frames-by-frame animation is simple, just need to define a animation-list in drawable or anim that contains multiple item, each item contains a picture and duration eg:<?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/pic1" "android:duration="/> <item android:drawable= "@drawable/pic2" android:duration= "/> <item android:drawable=" @ Drawable/pic3 "android:duration="/> <item android:drawable= "@drawable/pic4" android:duration= "500" /> <item android:drawable= "@drawable/pic5" android:duration= "$"/> <item android:drawable= "@drawable/pic6" android:duration= "/> <item android:drawable=" @drawable/pic7 "android:duration=" "/> <item android:drawable=" @drawable/pic8 "android:duration=",/> <item android: drawable= "@drawable/pic9" android:duration= "500 "/></animation-list> where oneshot means that it is not only looping once only needs to get animationdrawable call start in activity public void Startanimation (view view) { animationdrawable animationdrawable = ( animationdrawable) Imageview.getbackground (); Animationdrawable.start (); } public void StopAnimation (view view) { animationdrawable animationdrawable = (animationdrawable) Imageview.getbackground (); animationdrawable.stop (); } where ImageView has specified the background that animation-list <ImageView android:id= "@+id/image_ani" android:layout_width= "match_parent" android:layout_height= "400DP" android:background= "@drawable/animation_list"/> If the settings picture is android:src= "@drawable/animation_list", then get animationdrawable using imageview.getdrawable (); Of course can also not use the resource files to define the picture list, completely in code to implement animationdrawable drawable = new animationdrawable (); Drawable.addframe (Getdrawable (r.drawable.PIC1),; drawable.addframe (getdrawable (r.drawable.pic2),; drawable.addframe (getdrawable ( R.DRAWABLE.PIC2); imageview.setimagedrawable (drawable); Drawable.start (); 2. Motion Tween motion tweens are also called view animations, meaning that a view can make a series of simple changes within a container, such as ImageView can be easily changed (fade, rotate, pan, zoom) Tween animations can be defined in the Anim XML file, can also be implemented in code, However, it is recommended that XML be implemented so that there will be reusability alphaanimation <alpha> placement in res/anim/directory gradient Transparency animation effect Rotateanimation <rotate > placed in the res/anim/directory transfer rotation animation effect Scaleanimation <scale> Place the gradient resizing animation effect in the res/anim/directory Translateanimation <translate> placed in res/anim/directory picture conversion position move Animation Animationset <set> place in res/anim/directory A container that holds other animated elements alpha, scale, translate, rotate, or other set elements Common properties for all animation: Android:detachwallpaper Setdetachwallpaper (Boolean) is running on wallpaper android:duration setduration (long) animation duration, in milliseconds android:fillafter setfillafter ( Boolean) Whether the last state of the animation remains animated at the end of the Android:fillbefore Setfillbefore (Boolean) control whether to revert to the state before the animation is started when the animation ends android:fillenabled Setfillenabled (Boolean) and Android:fillbeFore effect same android:interpolator setinterpolator (interpolator) set Interpolator (specified animation effect, such as rebound, etc.) Android:repeatcount Setrepeatcount (int) Number of repetitions Android:repeatmode setrepeatmode (int) Repeat type has two values, reverse indicates reverse playback, restart means playback from the beginning Android:startoffset Setstartoffset (long) The time, in milliseconds android:zadjustment setzadjustment (int), that waits for the start function to begin running after it is called, indicating the position of the animated content on the z-axis (top/ Bottom/normal), default to normalalphaanimation animation float fromalpha float toalpha transparency, from 0 to 1: eg: Alphaanimation animation = new Alphaanimation (1, 0); animation.setduration (+); Animation.setrepeatcount (6); imageview.startanimation (animation); XML implementation: <?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "http://schemas.android.com/apk/res/ Android "> <alphaandroid:fromalpha=" 0 "android:toalpha=" 1 "android:duration="/></set> call: animation Animation = animationutils.loadanimation (This,r.anim.scale); Imageview.startanimation (AnimatION); of course, in set can be combined with other animations, such as rotation, Translate,scale. scaleanimation: Scale animation float FromX table is the scale from which to scale, with a value of 1 to 0, 1 for normal size float ToX to zoom to which range 1 to 0, 1 for normal size float FromY along the y axis Float Toy float Pivotx Relative to the x-axis of the zoom position float pivoty eg: scaleanimation animation = new Scaleanimation (0.5f, 1, 0.5f,1,500,500); animation.setduration (); imageview.startanimation (animation); Rotateanimation: Rotation animation float fromdegreesfloat todegrees Rotation, positive number indicates clockwise rotation, negative number indicates counterclockwise rotation float PIVOTX center point of rotation float pivoty & nbsp;eg:rotateanimation animation = new Rotateanimation (0, 360,500, $); animation.setduration (+); Imageview.startanimation (animation); Transtlateanimation: Translation animation float Fromxdelta translation start coordinate float toxdeltafloat fromydeltafloat toydelta eg: translateanimation animation = new Translateanimation (0, 0, 0); animation.setduration (+); Imageview.startanimation (animation); animationset: Combinations of various animations eg: aniMationset animationset = new Animationset (true); alphaanimation animation = new Alphaanimation (1, 0); Animati On.setduration (+); scaleanimation animation1 = new Scaleanimation (0.5f, 1, 0.5f,1); Animation1.setduration (; ) rotateanimation animation2 = new Rotateanimation (0, 360,400, +); Animation2.setduration (+); translateanimation Animation3 = new Translateanimation (0, 0, 0); Animation3.setduration (+); animationset.addanimation (animation); Animationset.addanimation ( Animation1); animationset.addanimation (animation2); animationset.addanimation (Animation3); Imageview.startanimation (Animationset); Property Animation Property animation in android can manipulate the properties of an object, That is, in a time interval to complete the properties of the object from one value to another is worth changing, so the function of property animation is very powerful, only you have this property, you can achieve animation effect. Of course, because the property animation is actually using the principle of reflection, so for this property must have a Get,set method to operate successfully, otherwise it will crash. The most important property animations are three classes Animatorset, Objectanimator and Valueanimator. Valueanimator is similar to a smooth transition generator. eg: valueanimator valueanimator = valueanimator.ofint (1, +); valueanimator.setduration (300); Valueanimator.addupdatelistener (New Valueanimator.animatorupdatelistener () { @Override Public void Onanimationupdate (Valueanimator valueanimator) { int value = Valueanimator.getanimatedvalue () } }); Valueanimator.start (); start and within 300 milliseconds, the Valueanimator will go from 1 to 100, and the resulting value is assigned to value. So if we want to implement some animations ourselves, such as a change in the void of a control, then we just need to set the value of its width constantly in the Onanimationupdate method, so we can make a smooth change. objectanimator inherit from Valueanimator. Objectanimator actually turns the animation of the width change like what we said above. Objectanimator internal use is reflection, so what we need is to pass to Objectanimator is the property of the space, and value is worth changing, so it is required that this property must have a Get,set method. Eg: objectanimator animator = Objectanimator.offloat (ImageView, "Translationx", 0, +); Animator.setduration (6000); Animator.start (); so the functionality that motion tweens can achieve, we can all achieve, such as RotationX, RotationY, Scalex,scaley and so on. of course, what if some properties don't have getset methods? Google givesThe solution is: one is to indirectly change the value of this property by customizing a wrapper class: Eg: private class myselfview{ private View view; private int width; Public Myselfview (view view) { This.view = view; } public int Getwi DTH () { return width; } public void setwidth (int width) { this.width = width; view.get Layoutparams (). width = width; view.requestlayout (); } } Define this class as long as: Objectanimator animator = objectanimator.offloat (new Myselfview (ImageView), "width", 0, +); Animator.setduration (4000); Animator.start (); Another approach is to use valueanimator to achieve For a collection of Animatorset animations, paly. With,before, after, etc., to achieve the sequence of animation of course there are playtogether (...). eg: Animatorset animatorset = new Animatorset (); animatorset.play (Animator1). with ( Animator2); Property animations can also be defined in XML to be more versatile. This XML animation should be placed under the resource file Res/animator eg: &NBSP; <objectanimator xmlns:android= "http://schemas.android.com/apk/res/android" android:duration= " 4000 " android:propertyname=" rotation " android:valuefrom=" 0 " android:valueto="/> " when called is also similar to tweened animation: Animator Animator = Animatorinflater.loadanimator (this, r.animator.obhectanimotr1) ; animator.settarget (ImageView); animator.start (); blog http://blog.csdn.net/lingling1420q/ article/details/38678493 is not bad,
Animation mechanism in Android