Animations can be divided into two categories: gradient (for example, fade-in and fade-out, rotation, movement, and scaling) and frame-by-frame, for example, a movie is usually displayed by multiple images at a certain interval.
Step 1 of using tweened animations:
1. Create an animationset object. The value of animationset = new animationset (Boolean B); // if the value of B is true, interpolator is shared.
2. Create corresponding animation objects (alphaanimation, rotateanimation, scaleanimation, and translateanimation) as needed)
3. Set the corresponding data for the animation object based on the needs of the software animation.
4. Add the animation object to the animationset object and use the addanimation method.
5. Use the control object to start executing the animationset
Step 2 of using tweened animations:
1. Create a folder named anim under the res folder
2. Create an XML file and add the set tag first. Modify the tag as follows:
<Set xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ Android: anim/accelerate_interpolator"> // interpolator defines the animation Change Rate
</Set>
3. Add the rotate, Alpha, scale, or translate tag to the tag, for example:
<Alpha
Android: fromalphi = "0.1"
Android: toalpha = "1.0"
Android: Duration = "3000"/>
<Rotate
Android: fromdegrees = "0"
Android: todegrees = "+ 350"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: Duration = "3000"/>
--- Note --- there are three ways to set the value of Android: Release TX:
1. Android: Using Tx = "50" This method uses absolute location
2. Android: Export Tx = "50%", which is located relative to the control
3. Android: Export Tx = "50% P ".
4. Use animationutils in the code to load the XML file and generate the animation object, animationutils. loadanimation
Frame-by-frame: Usage
1. Create an XML file in RES/drawable to define the animation sequence of animations. The following is an example:
<Animation-list
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: oneshot = "false">
<Item Android: drawable = "drawable/nv1"
Android: Duration = "500"/>
<Item Android: drawable = "drawable/nv2"
Android: Duration = "500"/>
<Item Android: drawable = "drawable/nv3"
Android: Duration = "500"/>
<Item Android: drawable = "drawable/nv4"
Android: Duration = "500"/>
</Animation-List>
2. imageview. setbackgroundresource ("ID of creating an XML file in RES/drawable ");
3. animationdrawable = (animationdrawable) imageview. getbackground ();
4. animationdrawable. Start ();