[ACCEPTED]-Set the interpolator for android animations in Java-android-animation

Accepted answer
Score: 87
setInterpolator(new BounceInterpolator());

0

Score: 15
anim.setInterpolator(context, android.R.anim.bounce_interpolator);

0

Score: 11

Update:

Android now supports real spring and physics 2 within animations. Its part of a backward 1 compatible lib. Link

For custom interpolators:

  1. Create a custom cubic bezier curve using this awesome site. And get the control points for the curve.
  2. Interpolator customInterpolator = PathInterpolatorCompat.create(cpX1,cpX2,cpY1,cpY2)
  3. Add this customInterpolator to any of your animation.

Added a gist. Some more here.

Score: 0

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.

More Related questions