Android Tween Animation

Source: Internet
Author: User

View Animation, which is displayed on the view tween Animation

Tween animation, essentially does not change the View object itself, only changes the way it is drawn

Two implementations, one defined in XML, one defined directly in the code

how XML is defined:Displacement Animation translate

<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:duration=" "    android:fromxdelta=" "    android:fromydelta=" 0 "    android: Toxdelta= "50%"     android:toydelta= "50%p"    android:repeatcount= "    android:repeatmode=" "Reverse" Android:fillafter= "true" ><!--repeatcount the number of times the animation repeats again Repeatmode   this time reverses the last effect fillafter the end of the animation, View stays at the end of the animation the  actual position of the view does not change 50%p relative to the parent layout 50%  relative to itself--></translate>
Rotate Animation Rotate
<?xml version= "1.0" encoding= "Utf-8"? ><rotate xmlns:android= "Http://schemas.android.com/apk/res/android"    android:duration= "    android:fromdegrees=" 0 "     android:todegrees=" -90 "    android:pivotx=" 50% "    android:pivoty= "50%"    android:repeatcount= "android:repeatmode="    reverse "    android:fillafter=" "True" ><!--fromdegrees= "0" Start angle todegrees= "90" End angle pivotx= "50%" center point xpivoty= "50%" Center point y--></rotate>
Transparency Gradient Animation Alpha
<?xml version= "1.0" encoding= "Utf-8"? ><alpha xmlns:android= "Http://schemas.android.com/apk/res/android"    android:duration= "    android:fromalpha=" 0 "    android:toalpha=" 1 "    android:fillafter=" true "    android:repeatcount= "android:repeatmode=" "    reverse" ><!--fromalpha start Transparency  0 Full transparent Toalpha end transparency  1 completely opaque--></alpha>
Zoom Animation Scale
<?xml version= "1.0" encoding= "Utf-8"? ><scale xmlns:android= "Http://schemas.android.com/apk/res/android"    android:duration= "    android:fromxscale=" 0.5 "    android:fromyscale=" 1 "    android:toxscale=" 3 "    android:toyscale= "2"    android:pivotx= "50%"    android:pivoty= "50%"    android:fillafter= "true"    Android:repeatcount= "android:repeatmode="    reverse "  ><!--scale scaling ratio--></scale>

Animation Set

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" Android:duration= "android:fillafter=" true "android:repeatcount=" android:repeatmode= "reverse" > &L T;scale android:fromxscale= "0.5" android:fromyscale= "1" android:pivotx= "50%" android:pivoty= "5 0% "android:repeatcount=" android:repeatmode= "reverse" android:toxscale= "3" android:toyscal        E= "2"/> <alpha android:fromalpha= "0" android:repeatcount= "android:repeatmode=" reverse " Android:toalpha= "1"/> <translate android:fromxdelta= "Ten" android:fromydelta= "0" Android oid:repeatcount= "android:repeatmode=" reverse "android:toxdelta=" 50% "Android:toydelta=" 50%p "/&gt    ; <rotate android:fromdegrees= "0" android:pivotx= "50%" android:pivoty= "50%" Android:repeatcou Nt= "Android:repe"Atmode= "Reverse" android:todegrees= " -100"/></set> 

The code loads these XML-defined animations

Animation translate = Animationutils.loadanimation (this, r.anim.translate); Imageview_translate.setbackground ( Getresources (). getdrawable (R.DRAWABLE.A11)); imageview_translate.startanimation (translate); Animation rotate = animationutils.loadanimation (this, r.anim.rotate); Imageview_rotate.setbackground (Getresources () . Getdrawable (R.DRAWABLE.A11)); imageview_rotate.startanimation (rotate); Animation Alpha = animationutils.loadanimation (this, r.anim.alpha); Imageview_alpha.setbackground (Getresources (). Getdrawable (R.DRAWABLE.A11)); Imageview_alpha.startanimation (Alpha); Animation scale = Animationutils.loadanimation (this, r.anim.scale); Imageview_scale.setbackground (Getresources (). Getdrawable (R.DRAWABLE.A11)); imageview_scale.startanimation (scale); Animation set = Animationutils.loadanimation (this, r.anim.set); Imageview_set.setbackground (Getresources (). Getdrawable (R.DRAWABLE.A11)); imageview_set.startanimation (set);

Pure Code creation tween Animation

Animationset animationset = new Animationset (true); animationset.addanimation (scale); Animationset.addanimation ( translate); animationset.addanimation (Alpha); animationset.addanimation (rotate); animationset.setduration (2000); Animationset.setrepeatcount, Animationset.setrepeatmode (Animation.restart);//animationset.setrepeatmode ( Animation.reverse); Imageview_set.setbackground (Getresources () getdrawable (R.DRAWABLE.A11)); imageview_ Set.startanimation (Animationset); Translateanimation translateanimation; Rotateanimation rotateanimation; Alphaanimation alphaanimation; Scaleanimation scaleanimation;//animation.relative_to_self relative to itself//animation.relative_to_parent relative to the parent view

set up an animation listener

Scale.setanimationlistener (New Animationlistener () {@Override//animation begins public void Onanimationstart (Animation Animation {} @Override//animation repeat public void Onanimationrepeat (Animation Animation) {} @Override//end of animation public void Onanimationend ( Animation Animation) {}});
Animation Insert Interpolator

An animated insert in animation XML and code that indicates the rate at which the animation moves over time

Android:interpolator = "@android: Anim/overshoot_interpolator"Overshootinterpolator

<!--  By default: Animations are applied evenly over time, and to change this effect you can use the insertion interpolator to set the insertion Accelerate_interpolator  similar acceleration is small, then it starts slowly and then grows fast.  variable motion  accelerate_decelerate_interpolator similar acceleration first large, small, first accelerated and then slowed down variable motion  anticipate_interpolatorthe change Starts backward then flings forward first minus (less than the start value), add (add to end) Anticipate_overshoot_interpolator first minus (less than the start value), plus ( Add to the end value a bit larger, and then fall back to the end value) overshoot_interpolator directly to the end value, and a bit larger than the end value, and then back to the end value  bounce_interpolator The change at the end of the bounce When the end value is reached, it will be small one to two times. Cycle_interpolator first quickly from the start to the end value, followed by the sine mode to continue the motion (left and right cut, up and down) linear_interpolator similar acceleration of 0, the rate is unchanged, uniform motion Default value used when inserting is not defined--   



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.