use of animations (3)
1 How to use animationset
What is Animationset
1 Animationset is a subclass of animation
21 Animationset contains a series of animation
3 set some common properties of animation (such as startoffset,duration, etc.) for Animationset, which can be included in animation inheritance in Animationset
Use steps : (similar to the example in 1 only has 2 animation effects)
Java code
- Animationset Animationset = new Animationset (ture);
- Alpahaanimation alpha = new Alphaanimation (...);
- Rotateanimation rotate = new Rotateanimation (...);
- Animationset.addanimation (Alpha);
- Animationset.addanimaion (rotate);
- Animationset.setduration (+);
- Animationset.setstartoffset (+);
- Imageview.startanimation (Animationset);
Animationset animationset = new Animationset (ture); Alpahaanimation alpha = new Alphaanimation (...); Rotateanimation rotate = new rotateanimation (...); Animationset.addanimation (Alpha); animationset.addanimaion (rotate); animationset.setduration (2000); Animationset.setstartoffset (+); imageview.startanimation (Animationset);
2 How to use Interpolator
Interpolator defines the rate of animation change and defines the following interpolator in the animations framework
Acceleratedecelerateinterpolator: Velocity changes slowly at the beginning and end of the animation, accelerating in the middle
Accelerateinterpolator: At the beginning of the animation, the rate changes slowly, and then accelerates
Cycleinterpolator: Animation loop plays a specific number of times, rate changes along the sine curve
Decelerateinterpolator: At the beginning of the animation, the rate changes slower, then slows down
Linearinterpolator: Change at a uniform rate
Set the Android:interpolator= "@android: Anim/accelerate_interpolator" in the set tag
And then there's a android:shareinterpolator= "true" from the name you can see that this is set for all the animations in set Interpolator
If you want to set it individually, set Shareinterpolator to False and define the Interpolator separately for each animation
The above is set in XML , if you want to set in code
Animationset.setinterpolator (New Accelerateinterpolator ()); (can also be set separately)
Note that there is a Boolean parameter in the Animationset constructor, which is the Shareinterpolator setting
3 How to use Frame-by-frame animations
1 Create an XML file in res/drawable that defines the animation animation play sequence Anim_nv.xml
XML code
- <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false">
- <item android:drawable="@drawable/nv1"
- android:duration=" /> "
- <item android:drawable="@drawable/nv2"
- android:duration=" /> "
- <item android:drawable="@drawable/nv3"
- android:duration=" /> "
- <item android:drawable="@drawable/nv4"
- android:duration=" /> "
- </animation-list>
<animation-list xmlns:android= "Http://schemas.android.com/apk/res/android" android:oneshot= "false" >< Item android:drawable= "@drawable/nv1" android:duration= "/><item android:drawable=" @drawable/nv2 "Android :d uration= "/><item android:drawable=" @drawable/nv3 "android:duration="/><item android: drawable= "@drawable/nv4" android:duration= "/></animation-list>
2 Setting a background resource for ImageView
Java code
- Imageview.setbackgroundresource (R.drawable.anim_nv);
Imageview.setbackgroundresource (R.drawable.anim_nv);
3 Get animationdrawable through ImageView
Java code
- Animationdrawable animationdrawable = (animationdrawable) imageview.getbackground ();
Animationdrawable animationdrawable = (animationdrawable) imageview.getbackground ();
3 Performing animations
Java code
- Animationdrawable.start ();
Animationdrawable.start ();
Use of Animationset