Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save EmmanuelGuther/22ae0417a8620e0563e16903f26236c8 to your computer and use it in GitHub Desktop.

Select an option

Save EmmanuelGuther/22ae0417a8620e0563e16903f26236c8 to your computer and use it in GitHub Desktop.
A kotlin extension to set numbers in textview one by one
fun TextView.showCountIncrementAnimation(from: Int? = 0, to: Int?) {
var duration: Long? = null
val animator = ValueAnimator()
animator.setObjectValues(from, to)// here you set the range, from 0 to "count" value
animator.addUpdateListener { animation -> this.text = animation.animatedValue.toString() }
duration = when (to) {
in 0..4 -> 200
in 5..10 -> 1000
in 11..50 -> 3000
else -> 2000
}
animator.duration = duration
animator.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment