-
-
Save siddhraj-sinh/842ff7589ba6443ee0156bb9a45b26f6 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