Created
August 1, 2019 10:29
-
-
Save EmmanuelGuther/22ae0417a8620e0563e16903f26236c8 to your computer and use it in GitHub Desktop.
A kotlin extension to set numbers in textview one by one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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