[ACCEPTED]-Set the interpolator for android animations in Java-android-animation
Accepted answer
setInterpolator(new BounceInterpolator());
0
anim.setInterpolator(context, android.R.anim.bounce_interpolator);
0
Update:
Android now supports real spring and physics 2 within animations. Its part of a backward 1 compatible lib. Link
For custom interpolators:
- Create a custom cubic bezier curve using this awesome site. And get the control points for the curve.
Interpolator customInterpolator = PathInterpolatorCompat.create(cpX1,cpX2,cpY1,cpY2)
- Add this customInterpolator to any of your animation.
Thanks to amalBit I wrote an interpolator with 2 a PathInterpolator
for a ProgressBar
in Kotlin.
val path = Path()
path.lineTo(0.1f, 0.2f)
path.lineTo(0.7f, 0.9f)
path.lineTo(1f, 1f)
val animation = ObjectAnimator.ofInt(progress_bar, "progress", 0, 100)
animation.duration = 2000
animation.interpolator = PathInterpolatorCompat.create(path)
animation.addListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animator: Animator) {}
override fun onAnimationEnd(animator: Animator) {
finish()
}
override fun onAnimationCancel(animator: Animator) {}
override fun onAnimationRepeat(animator: Animator) {}
})
animation.start()
See more examples at 1 https://www.programcreek.com/java-api-examples/index.php?api=android.view.animation.PathInterpolator.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.