Skip to content

Instantly share code, notes, and snippets.

@siddhraj-sinh
Forked from MarkNjunge/Animated elipses.kt
Created May 28, 2021 13:08
Show Gist options
  • Save siddhraj-sinh/842ff7589ba6443ee0156bb9a45b26f6 to your computer and use it in GitHub Desktop.
Save siddhraj-sinh/842ff7589ba6443ee0156bb9a45b26f6 to your computer and use it in GitHub Desktop.
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