Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Animated ellipses in Android
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