Create a new folder under res named Anim, creating an XML file, such as creating a a1.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<set xmlns:android= "Http://schemas.android.com/apk/res/android" >
Write an animation here
</set>
Alpha: Gradient Transparency effect
Rotate: Rotate animation effect
Scale: Stretch animation effect
Translate: Panning animation effect
Use the following XML to create animation-part of the animation, details see source code:
Alpha: Gradient Transparency effect- from there to none
A1.xml
<set xmlns:android= "Http://schemas.android.com/apk/res/android" > <alpha android:duration= "3000 " android:fromalpha=" 1.0 " android:toalpha=" 0.0 "/></set>
rotate: Rotate animation effect-Clockwise
Rotate.xml
<rotate android:duration= "android:fromdegrees=" 0 " android:interpolator=" @android: anim/ Accelerate_decelerate_interpolator " android:pivotx=" 50% " android:pivoty=" 50% " android:todegrees = "+350"/>
scale: Stretch animation effect-zoom to the lower-right corner
Scale.xml
<scale android:duration= "" " android:fillafter=" false " android:fromxscale=" 1.0 " android: Fromyscale= "1.0" android:interpolator= "@android: Anim/accelerate_decelerate_interpolator" android: pivotx= "100%" android:pivoty= "100%" android:toxscale= "0" android:toyscale= "0"/>
Translate: Panning animation effect-top to bottom
Translate.xml
<translate android:duration= "android:fromxdelta=" 0 " android:fromydelta=" 0 " android: Toxdelta= "0" android:toydelta= "/>"
If it is a collection of animations, it is loaded in order under the set node. The following rotation and movement of the set
<set xmlns:android= "Http://schemas.android.com/apk/res/android" > <rotate android:duration= " " android:fromdegrees=" 0 " android:interpolator=" @android: Anim/accelerate_decelerate_interpolator " android:pivotx= "50%" android:pivoty= "50%" android:todegrees= "+350"/> <translate android:duration= "Android:fromxdelta=" 0 " android:fromydelta=" 0 " android:toxdelta=" 0 " android:toydelta="/></set>
Write a tool class to load this animation
Animaxmlutils.java
/** * Animation using XML design * */public class Animaxmlutils {private static Animation anim;/** * Gradient transparent animation, transparency: 1.0~0.0 * * @return */pu Blic static Animation Alphafrom1to0 (context context) {Anim = animationutils.loadanimation (context, r.anim.a1); return Anim;} /** * Gradient Transparent animation, transparency: 1.0~0.0 * * @return */public static Animation alphafrom0to1 (context context) {Anim = Animationutils.load Animation (context, R.ANIM.A2); return anim;} /** * Rotate animation, clockwise * * @return */public static Animation rotateticlockwise (context context) {Anim = Animationutils.loadani Mation (context, r.anim.rotate); return anim;} /** * Rotate animation, counter-clockwise * * @return */public static Animation rotateanticlockwise (context context) {Anim = Animationutils.loada Nimation (context, r.anim.rotate1); return anim;} /** * Telescopic animation, from have to no * * @return */public static Animation scalefrom1to0 (context context) {Anim = Animationutils.loadanimation (context, R.anim.scale); return anim;} /** * Telescopic animation, from have to no * * @return */public static Animation scalefrom0to1 (context context) {Anim = anImationutils.loadanimation (context, r.anim.scale1); return anim;} /** * Pan animation, from top to bottom * * @return */public static Animation Translatetoptobottom (context context) {Anim = Animationutils.loadan Imation (context, r.anim.translate); return anim;} /** * Pan animation, from bottom to top * * @return */public static Animation translatebottomtotop (context context) {Anim = Animationutils.loadan Imation (context, r.anim.translate1); return anim;} /** * Four Animation sets * * @return */public static Animation Animationroaandtranset (context context) {Anim = Animationutils.loadani Mation (context, r.anim.aniset); return anim;}}
:
SOURCE Download: http://download.csdn.net/detail/forwardyzk/8314155
Android builds basic XML animations