to make the user more comfortable in some cases, the use of animation is so very necessary. Android in 3.0 once supports two animated tween anime frame animations. Tween animations support simple panning, zooming, rotating, and gradients. Frame animations mimic animated animations by a series of images, and the new animations that are introduced after Android 3.0 are property animations (propertiesanimation). Android share a simple and interesting animation effect is to take advantage of the property animation.
Today we mainly come to learn tween animation is also view animation.
View animations can only be applied to view objects and only support a subset of properties. and for a view animation, it simply changes the location of the view object's drawing. Instead of changing the view object itself, for example, there is currently a button with the coordinates (200,200) moved to (200,500) by panning the animation, but you click on the moved button is no matter what effect, such as:
Knowing this premise, we begin to understand the basic use of view animation. Animations can be written in Java code or in XML
1, panning Animation
<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android " android:duration=" " android:fillafter=" true " android:fromxdelta=" 0% " android: Fromydelta= "0%" android:repeatcount= " android:repeatmode=" restart "android:toxdelta=" 0% " Android:toydelta= "70%" ></translate>
Duration animation time. Fillafter keep the animation after the state, Fromxdelta start x position, Fromydelta start y position, repeatcount repeated times, Repeatmode Repeat mode restart for the positive sequence reverse in reverse, In Java code
Animation Animation =animationutils.loadanimation (this, r.anim.tran_btn);
View.startanimation (animation);
<span style= "FONT-SIZE:18PX;" >animation animation2 = new Translateanimation (0, 0, 0); Animation2.setduration (+); animation2.setrepeatcount Animation2.setrepeatmode (Animation.restart); Button.startanimation (Animation2);</span>
New Translateanimation (Fromxdelta, Toxdelta, Fromydelta, Toydelta)
I'm sure everyone knows what they mean.
2. Rotate animation
<?XML version= "1.0" encoding= "Utf-8"? ><rotate xmlns:android= "Http://schemas.android.com/apk/res/android" android:duration= "android:fromdegrees=" 0 " android:todegrees=" android:pivotx= "50% " Android:pivoty= "50%" ></rotate>
Roughly ibid. Center point of pivot rotation.
Animation animation2 = new Rotateanimation (0, 0, 0); Animation2.setduration (+); Button.startanimation ( Animation2);
3, gradient animation
<span style= "FONT-SIZE:18PX;" ><?XML version= "1.0" encoding= "Utf-8"? ><alpha xmlns:android= "Http://schemas.android.com/apk/res/android" android:duration= "android:fromalpha=" 1.0 " android:toalpha=" 0.0 "></alpha></span>
Actually, look, one of the rest is comprehend by analogy.
<span style= "FONT-SIZE:18PX;" >animation Animation = new Alphaanimation (1, 0); Animation.setduration (+); button.startanimation (Animation); </span>
4. Zoom Animation
<?xml version= "1.0" encoding= "Utf-8"? ><scale xmlns:android= "Http://schemas.android.com/apk/res/android" android:duration= "android:fromxscale=" 0.0 " android:fromyscale=" 1.0 "android:pivotx=" 50% " android:pivoty=" 50% " android:toxscale=" 1.0 "android:toyscale=" 1.0 " ></scale>
OK, the next four basic animations are simply finished. But sometimes we may have some special needs. For example, to play a set of animations, we can use set
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <rotate android:duration= "0" android:fromdegrees= " android:pivotx=" 50% " Android:pivoty= "50%" android:todegrees= "/> <alpha android:duration=" " android: Fromalpha= "1.0" android:toalpha= "0.0"/></set>
This is rotated at the same time as the gradient play, assuming that the play in turn only need to add Startoffset
<?XML version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <rotate android:duration= "android:fromdegrees=" 0 " android:pivotx=" 50% " android: Pivoty= "50%" android:todegrees= "/> <alpha android:duration= " " android:fromalpha=" "1.0" android:startoffset= "android:toalpha=" /></set> "0.0"
This will enable playback in turn. But sometimes we want a special effect such as the acceleration of animation, when we can use interpolator,animation.setinterpolator (New Accelerateinterpolator ());
Acceleratedecelerateinterpolator rate changes are slower at the beginning and end of the animation. In the middle of time to accelerate
Accelerateinterpolator rate changes are slower at the beginning of the animation. and start accelerating.
Anticipateinterpolator starts and then moves backwards.
Anticipateovershootinterpolator start with the back and then throw a certain value back to the last value
Bounceinterpolator animation at the end of the play
Cycleinterpolator Animation Loop plays a specific number of times, rate changes along the sine curve
Decelerateinterpolator at the beginning of the animation and then slowly
Linearinterpolator change at constant rate
Overshootinterpolator forward a certain value before returning to its original position.
Thank you for your patience in reading. Do not accumulate Kuibu not even thousands of miles, there are any questions can also leave a message.
Android Animation specifically explains the view animation