Android Animation Interpolator and Custom Animation Tracks

 /**
         * 设置加速器
*/
fun interpolatorAnimator(view: View) {
            val animator1 = ObjectAnimator.ofFloat(view, "alpha", 1f, 0.5f, 1f)
            val animator2 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0.5f, 1f)
            val animator3 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0.5f, 1f)
            val                  animator4 = ObjectAnimator.ofFloat(view, "translationX", 0f, 300f,0f)
            val animator5 = ObjectAnimator.ofFloat(view, "translationY", 0f, 500f,0f)
            var animatorSet = AnimatorSet()
            animatorSet.duration = 300
            animatorSet.interpolator = AccelerateDecelerateInterpolator()
//            animatorSet.interpolator=AccelerateInterpolator()
//            animatorSet.interpolator=AnticipateInterpolator()
            animatorSet.playTogether(animator1, animator2, animator3, animator4, animator5)
            animatorSet.start()
        }

        /**
          * Implement parabola effect
 * x : uniform speed
 * y : acceleration y = 1/2*g*t*t
          * use estimator to implement
 */
 fun parabolaAnimator (view: View) {
             var valueAnimator = ValueAnimator()                                   
            valueAnimator.duration = 3000
 valueAnimator.setObjectValues (PointF())
             // Evaluator -- Define calculation rules
 valueAnimator.setEvaluator { fraction , startValue , endValue ->
 run {
 var pointF = PointF()                                                            
                    pointF.x = 200f * (fraction * valueAnimator.duration / 1000)//x=v*t
                    pointF.y = 0.5f * 9.8f * (fraction * valueAnimator.duration / 1000) * (fraction * valueAnimator.duration / 1000)//y = 1/2*g*t*t
                    pointF
                }
            }
            valueAnimator.addUpdateListener { animation ->
run {
var animatedValue = animation.animatedValue                                     as PointF
                    view.x = animatedValue.x
                    view.y = animatedValue.y
}
            }
valueAnimator.start()                            
        }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325581146&siteId=291194637