Skip to content

Instantly share code, notes, and snippets.

@MarkNjunge
Created December 29, 2018 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MarkNjunge/d10119b758e51708ad276717e3bb7a15 to your computer and use it in GitHub Desktop.
Save MarkNjunge/d10119b758e51708ad276717e3bb7a15 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