Recently learned the following animation, roughly divided into: property animation (inheritance value animation), frame animation, tweened animation. The following is a description of each of the XML file configurations
First: normal animation:
Divided into translate,scale,alpha,rotate, four kinds of animation configuration big questions the same;
<translate xmlns:android= "http://schemas.android.com/apk/res/android" android:duration= " Android:fromxdelta= "0" android:interpolator= "@anim/cycle_7" android:toxdelta= "/>"
Explain the Interpolator this property, which can set some end animation at the end of the animation, such as the number of vibrations back and forth cycle, as well as overshoot.
<cycleinterpolator xmlns:android= "http://schemas.android.com/apk/res/android" android:cycles= "7"/>
This property indicates that the vibration is 7 times back and forth. The other three animations also have the same configuration, and if you want to set up a collection of multiple animations, you can wrap a layer of set properties outside the XML file.
You can also set up motion tweens in your code.
public void translate (View v) {//ta = new Translateanimation (ten, +, +); ta = new Translateanimation (Animation.relati Ve_to_self, 1, animation.relative_to_self, 2, Animation.relative_to_self, -0.5f, Animation.relative_to_self, 1.5f); /Set Playback time Ta.setduration (2000);//Set the number of repetitions ta.setrepeatcount (1); Ta.setrepeatmode (animation.reverse); iv.startanimation (TA);} public void scale (View v) {//sa = new scaleanimation (FromX, ToX, FromY, ToY, Iv.getwidth ()/2, Iv.getheight ()/2); sa = NE W scaleanimation (0.5f, 2, 0.1f, 3, Animation.relative_to_self, 0.5f, Animation.relative_to_self, 0.5f); Sa.setduration ( 2000);//The end position of the filled animation sa.setrepeatcount (1); Sa.setrepeatmode (Animation.reverse); Sa.setfillafter (true); Iv.startanimation (SA);} public void Alpha (View v) {AA = new alphaanimation (0, 1); aa.setduration (+); Sa.setrepeatcount (1); Iv.startanimation ( AA);} public void rotate (View v) {ra = new rotateanimation (0, 720, animation.relative_to_self, 0.5f, animation.relative_to_self , 0.5f); Ra.setduration (Ra.setrepeatcoun);T (1); Ra.setrepeatmode (Animation.reverse); Iv.startanimation (RA);} public void Fly (View v) {Animationset set = new Animationset (false); set.addanimation (TA); set.addanimation (SA); Set.addanimation (RA); set.addanimation (AA); iv.startanimation (set);}
Then there are frame animations, which are generally less frequent, and are used in the app's opening animation.
<animation-list xmlns:android= "Http://schemas.android.com/apk/res/android" Android:oneshot= "false" > <item android:drawable= "@drawable/g1" android:duration= "$"/> <item android:d rawable= "@drawable/g2" android:duration= "/> <item android:drawable=" @drawable/g3 "android:duration=" 200 " /> <item android:drawable= "@drawable/g4" android:duration= "$"/> <item android:drawable= "@drawable/g5" android:duration= "/> <item android:drawable=" @drawable/g6 "android:duration="/> <item Android :d rawable= "@drawable/g7" android:duration= "/> <item android:drawable=" @drawable/g8 "android:duration=" "/> <item android:drawable=" @drawable/g9 "android:duration=" "/> <item android:drawable=" @drawabl E/g10 "android:duration=" android:drawable= "/> <item/g11" @drawable android:duration= "/></" Animation-list>
OneShot: Whether the animation is performed only once, Duration: The duration of the animation.
The Frame animation resource file is specified as the background iv.setbackgroundresource of IV (R.drawable.frameanimation);//Gets the background of the IV animationdrawable AD = ( animationdrawable) Iv.getbackground (); Ad.start ();
Invokes a frame animation in a class.
The following properties are animated: The difference between this animation and frame animation is that he is actually moving the displacement.
public void translate (View v) {//translateanimation ta = new translateanimation (0, 0, 0);//ta.setduration (+);//ta . Setfillafter (True);//iv.startanimation (TA);//target: Which component the animation acts on Objectanimator oa = Objectanimator.offloat (iv, " Translationx ",", ",", "," (oa.setduration); Oa.setrepeatcount (1); Oa.setrepeatmode (Valueanimator.reverse) ; Oa.start ();} public void scale (View v) {objectanimator OA = Objectanimator.offloat (iv, "ScaleX", 1, 1.6f, 1.2f, 2); Oa.setduration (2000) ; Oa.start ();} public void Alpha (View v) {objectanimator OA = Objectanimator.offloat (iv, "Alpha", 0, 0.6f, 0.2f, 1); Oa.setduration (2000); Oa.start ();} public void rotate (View v) {objectanimator OA = Objectanimator.offloat (iv, "RotationY", 0,, n); Oa.setduration (20 Oa.setrepeatcount (1); Oa.setrepeatmode (Valueanimator.reverse); Oa.start (); public void Fly (View v) {Animatorset set = new Animatorset (); Objectanimator oa1 = Objectanimator.offloat (iv, "Translationx ", ten, (+), oa1.setduration); Oa1.setrepeatcouNT (1); Oa1.setrepeatmode (valueanimator.reverse); Objectanimator oa2 = Objectanimator.offloat (iv, "Translationy", 10, (oa2.setduration); Oa2.setrepeatcount (1); Oa2.setrepeatmode (valueanimator.reverse); objectanimator OA3 = Objectanimator.offloat (iv, "ScaleX", 1, 1.6f, 1.2f, 2); oa3.setduration (+); Oa3.setrepeatcount (1); O A3.setrepeatmode (valueanimator.reverse); Objectanimator oa4 = Objectanimator.offloat (iv, "rotation", 0, N/A, a); O A4.setduration (+); Oa4.setrepeatcount (1); Oa4.setrepeatmode (valueanimator.reverse);//set to fly// Set.playsequentially (OA1, OA2, OA3, OA4);//Set Fly Set.playtogether (OA1, OA2, OA3, OA4); Set.start ();} public void XML (View v) {Animator at = Animatorinflater.loadanimator (this, r.animator.objanimator);// Set which component At.settarget (iv); At.start ();}Similarly, he can also load XML animations.
<set xmlns:android= "http://schemas.android.com/apk/res/android" ><objectanimator android: Propertyname= "Translationx" android:duration= "android:repeatcount=" 1 " android:repeatmode=" Reverse " android:valuefrom=" -100 " android:valueto=" > </objectanimator></set >
Android Animation settings