Android Animation classification will not say, mainly about the two ways to use the animation: 1. Generate and use animations through code (not conducive to reuse) 2generate and use animations from an XML file (more convenient and highly reusable). 1. Generating animations from code? 12345//InitializeAnimation scaleanimation =NewScaleanimation (0.1f, 1.0f,0.1f,1.0f);//Set Animation timeScaleanimation.setduration (500); This. Startanimation (scaleanimation);//InitializeAnimation translateanimation =NewTranslateanimation (0.1f, 100.0f,0.1f,100.0f);//Set Animation time translateanimation.setduration (+); this.startanimation (translateanimation);steps:1. Declare an animation 2. Set animation time (you can also set other properties such as number of animations) 3. Use animations. If a control uses two or more animations at the same time, it needs to be implemented by Animationset (animation set). For example, a imageview uses the above two animations simultaneously, the code is as follows://Initializing translate animationsTranslateanimation =NewTranslateanimation (0.1f, 100.0f,0.1f,100.0f); //Initialize Alpha animationAlphaanimation =NewAlphaanimation (0.1f, 1.0f); //Animation SetAnimationset set =NewAnimationset (true); Set.addanimation (translateanimation); Set.addanimation (alphaanimation); //Set animation time (action to each animation)Set.setduration (1000); This. Startanimation (set);2. Generate an animated Ani.xml file from an XML layout file:<set xmlns:android= "Http://schemas.android.com/apk/res/android" > <translate android:interpolator= "@ Android:anim/accelerate_interpolator "android:fromxdelta=" 0 "android:toxdelta=" 0 "android:fromydelta=" 0 "Android: Toydelta= " -380" android:duration= "> <scale android:interpolator=" @android: Anim/accelerate_interpolator "Android:fromxscale=" 1.0 "android:toxscale=" 0.2 "android:fromyscale=" 1.0 "android:toyscale=" 0.2 "android:pivotx=" 50% "android:pivoty=" 50% "android:duration=" ></scale></translate></alpha></set>the above XML file has been animated, so just use it in the activity, and the code looks like this:? 1Animation Animation= Animationutils.loadanimation ( This. GetContext (), R.anim.ani); With the above line of code, you can directly use the animation in the XML file.
Two ways to use Android animations.