使用案例
autoIncrement(tvNum, 0.0f, 0.0f, 2000)
/*
* @params target 目标view
* @parmas start 开始金额
* @parmas end 最大金额
* @parmas duration 动画时间
*/
fun autoIncrement(target: TextView, start: Float,end: Float, duration: Long ) {
val animator = ValueAnimator.ofFloat(start, end)
animator.addUpdateListener(object : AnimatorUpdateListener {
val evalutor = FloatEvaluator()
val format: DecimalFormat = DecimalFormat("####0.00#")
override fun onAnimationUpdate(animation: ValueAnimator) {
val fraction = animation.animatedFraction
val currentValue = evalutor.evaluate(fraction, start, end)
target.setText(format.format(currentValue))
}
})
animator.duration = duration
animator.start()
}
网友评论