Created
December 29, 2018 09:51
-
-
Save MarkNjunge/d10119b758e51708ad276717e3bb7a15 to your computer and use it in GitHub Desktop.
Animated ellipses in Android
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
val spannableString = SpannableString("Loading...") | |
val transparentColorSpan = ForegroundColorSpan(Color.TRANSPARENT) | |
ValueAnimator.ofInt(0, 4).apply { | |
repeatCount = 10 | |
duration = 1000 | |
addUpdateListener { valueAnimator -> | |
val dotsCount = valueAnimator.animatedValue as Int | |
if (dotsCount < 4) { // 4 is the number of ellipses + 1 | |
spannableString.setSpan( | |
transparentColorSpan, | |
7 + dotsCount, // The length of your string WITHOUT the ellipses + dotsCount | |
10 // The total length of your string, WITH the ellipses | |
, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) | |
tvLoading.text = spannableString | |
} | |
} | |
}.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment