preface
In the previous section, we realized rotation, displacement animation, etc., we will find that it is always uniform, but what if we need to do an accelerated rotation animation? Interpolator is another common attribute of animation
- Android Custom View directory
Android has already added nine interpolators for us
- AccelerateDecelerateInterpolator slowly, at the end of the animation start and middle speed
- AccelerateInterpolator acceleration
- Argateinterpolator will be started backwards and then forward
- AnticipateOvershootInterpolator at the start of the backward and forward to jilt a certain value returns the value of the final
- BounceInterpolator BounceInterpolator plays at the end of the animation
- CycleInterpolator animation plays looping a specific number of times, changing the rate along a sine curve
- DecelerateInterpolator deceleration
- The LinearInterpolator changes at a constant rate
- OvershootInterpolator throws a value forward before returning to the original position
We implement a rotation animation
rotateAnimation = new RotateAnimation(0.3600, RotateAnimation.RELATIVE_TO_SELF, 0.5 f,
RotateAnimation.RELATIVE_TO_SELF, 0.5 f);
rotateAnimation.setFillAfter(true);
rotateAnimation.setDuration(5000);
Copy the code
Set the interpolator
switch (view.getId()) {
case R.id.btn_1:
/ / AccelerateDecelerateInterpolator slowly, at the end of the animation start and middle speed
rotateAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_2:
/ / AccelerateInterpolator acceleration
rotateAnimation.setInterpolator(new AccelerateInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_3:
Or argateinterpolator will be started backwards and then forward
rotateAnimation.setInterpolator(new AnticipateInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_4:
/ / AnticipateOvershootInterpolator at the start of the backward and forward to jilt a certain value returns the value of the final
rotateAnimation.setInterpolator(new AnticipateOvershootInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_5:
//BounceInterpolator BounceInterpolator plays at the end of the animation
rotateAnimation.setInterpolator(new BounceInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_6:
//CycleInterpolator animation plays looping a specific number of times, changing the rate along a sine curve
rotateAnimation.setInterpolator(new CycleInterpolator(0.5 f));
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_7:
/ / DecelerateInterpolator slowdown
rotateAnimation.setInterpolator(new DecelerateInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_8:
// The LinearInterpolator changes at a constant rate
rotateAnimation.setInterpolator(new LinearInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
case R.id.btn_9:
//OvershootInterpolator throws a value forward before returning to the original position
rotateAnimation.setInterpolator(new OvershootInterpolator());
tvDemo.startAnimation(rotateAnimation);
break;
}
Copy the code
Since the animation is a bit fast and the recorded GIF file is quite large and doesn’t work well, I’ll post an APK here for you to see for yourself
Finally, present the source codegithub
Resources: Animation in the Custom controls trilogy