Android Animation Interpolator

Source: Internet
Author: User

Note: Scale should be added to set before translate


Interpolator the time interpolation class to define the speed of the animation transformation. It can realize acceleration, deceleration and repetition of alpha/scale/translate/rotate animation. The Interpolator class is actually an empty interface that inherits from the Timeinterpolator,timeinterpolator time interpolator allowing animations to perform nonlinear motion transformations, such as acceleration and speed limiting, where there is only one method in the interface float getinterpolation (float input) this method. the value passed in is a 0.0~1.0 value, and the return value can be less than 0.0 or greater than 1.0.






Common Inheritance Classes

  1. acceleratedecelerateinterpolator============ animation starts and ends where the rate change is slower and accelerates in the middle.
  2. The accelerateinterpolator=================== animation starts at a slower rate and then starts to accelerate.
  3. Anticipateinterpolator ================== starts back and then dumps forward.
  4. When the anticipateovershootinterpolator============= starts, it returns to the last value after a certain value is thrown backwards and forwards.
  5. bounceinterpolator===================== when the animation ends.
  6. cycleinterpolator====================== The animation loop plays a specific number of times, the rate changes along the sinusoidal curve.
  7. decelerateinterpolator=================== is fast and slow at the beginning of the animation.
  8. The linearinterpolator====================== is changed at constant rate.
  9. overshootinterpolator==================== a certain value before returning to its original position.
  10. pathinterpolator======================== added is that you can define the path coordinates, and then you can run according to the path coordinates, note that the coordinates are not XY, but one direction, that is, I can go from 0~1, then bounce back to 0.5. Then it bounces to 0.7 to 0.3 until the end of the last time.

Several commonly used interpolator source code: Linearinterpolator linear interpolator, return the input value directly.
/** * A interpolator where the rate of change is  constant  * */@HasNativeInterpolator public  class L Inearinterpolator implements Interpolator, nativeinterpolatorfactory {public        linearinterpolator () {      }            Public Linearinterpolator (context context, AttributeSet attrs) {      } public            float getinterpolation (float input) {          return input;      }        /** @hide *      /@Override public      long Createnativeinterpolator () {          return Nativeinterpolatorfactoryhelper.createlinearinterpolator ();      }  }  

Decelerateinterpolator

you can animate property settings through XML, which can be set by XML The Mfactor variable, whose value is 1.0 by default;

/** * An interpolator where the rate of change starts out quickly and and then decelerates.      * */@HasNativeInterpolator public class Decelerateinterpolator implements Interpolator, Nativeinterpolatorfactory { Public Decelerateinterpolator () {}/** * Constructor * * @param factor degree to which the Animation should be eased. Setting factor to 1.0f produces * an upside-down y=x^2 parabola. Increasing factor above 1.0f makes exaggerates the * ease-out effect (i.e., it starts even faster and ends eve      NS slower) */public Decelerateinterpolator (float factor) {mfactor = factor; } public Decelerateinterpolator (context context, AttributeSet Attrs) {This (Context.getresources (), Contex      T.gettheme (), attrs); }/** @hide */Public Decelerateinterpolator (Resources res, Theme Theme, AttributeSet attrs) {Typeda          Rray A; if (theme! = null) {a = theme. Obtainstyledattributes (Attrs, r.styleable.decelerateinterpolator, 0, 0);          } else {a = Res.obtainattributes (Attrs, r.styleable.decelerateinterpolator);            } mfactor = A.getfloat (R.styleable.decelerateinterpolator_factor, 1.0f);      A.recycle ();          } public float getinterpolation (float input) {float result;          if (Mfactor = = 1.0f) {result = (float) (1.0f-(1.0f-input) * (1.0f-input));          } else {result = (float) (1.0f-math.pow ((1.0f-input), 2 * mfactor));      } return result;        } private float mfactor = 1.0f; /** @hide */@Override public long Createnativeinterpolator () {return nativeinterpolatorfactoryhelper.      Createdecelerateinterpolator (Mfactor);   }  }

look at the top three of the first line of Java:
public class Sine {public            static float  easeIn (float t,float B, float C, float d) {          return-c * (float) math.c OS (T/D * (MATH.PI/2)) + C + B;      }            public static float  EaseOut (float t,float B, float C, float d) {          return c * (float) Math.sin (t/d * (MATH.PI/2)) + b;        }            public static float  easeinout (float t,float B, float C, float d) {          RETURN-C/2 * ((float) math.cos (math.pi*t/d) -1) + B;      }        }  


Although Java also has, but say this how to use Ah, with the above interpolator how to link up ah?

an easy way to do this: first set the D total time to a fixed value of 1.0, set the start value of B to 0.0 to set the end value to 1.0, and then the T as the above Interpolator float getinterpolation (float input); I can use it.

Give me a case.
/**  * Created by Qiujuer on 2015/1/5.  *  /public class Insineinterpolator implements interpolator{public      static float  easeIn (float t,float B, Float C, float d) {          return-c * (float) math.cos (t/d * (MATH.PI/2)) + C + B;      }        @Override Public      float getinterpolation (float input) {          return easeIn (input, 0, 1, 1);      }  }  


Use
Animatorset  manimatorset = new Animatorset ();  Manimatorset.playtogether (Apaintx, Apainty, Aradius, abackground);  Manimatorset.setinterpolator (New Insineinterpolator ());  Manimatorset.start ();  

It can be seen using the same as the above Android, of course, this is just a case, the specific use of you can be packaged, if not change the main part.
/** * An interpolator where the rate of change starts out quickly and and then decelerates.      * */@HasNativeInterpolator public class Decelerateinterpolator implements Interpolator, Nativeinterpolatorfactory { Public Decelerateinterpolator () {}/** * Constructor * * @param factor degree to which the Animation should be eased. Setting factor to 1.0f produces * an upside-down y=x^2 parabola. Increasing factor above 1.0f makes exaggerates the * ease-out effect (i.e., it starts even faster and ends eve      NS slower) */public Decelerateinterpolator (float factor) {mfactor = factor; } public Decelerateinterpolator (context context, AttributeSet Attrs) {This (Context.getresources (), Contex      T.gettheme (), attrs); }/** @hide */Public Decelerateinterpolator (Resources res, Theme Theme, AttributeSet attrs) {Typeda          Rray A; if (theme! = null) {a = theme. Obtainstyledattributes (Attrs, r.styleable.decelerateinterpolator, 0, 0);          } else {a = Res.obtainattributes (Attrs, r.styleable.decelerateinterpolator);            } mfactor = A.getfloat (R.styleable.decelerateinterpolator_factor, 1.0f);      A.recycle ();          } public float getinterpolation (float input) {float result;          if (Mfactor = = 1.0f) {result = (float) (1.0f-(1.0f-input) * (1.0f-input));          } else {result = (float) (1.0f-math.pow ((1.0f-input), 2 * mfactor));      } return result;        } private float mfactor = 1.0f; /** @hide */@Override public long Createnativeinterpolator () {return nativeinterpolatorfactoryhelper.      Createdecelerateinterpolator (Mfactor);   }  }


Top
0

Android Animation Interpolator

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.