Skip to content

Instantly share code, notes, and snippets.

@siscofran999
Last active June 18, 2022 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save siscofran999/e0a73dc7db26b2e06f822751510abfea to your computer and use it in GitHub Desktop.
Save siscofran999/e0a73dc7db26b2e06f822751510abfea to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val progress = findViewById<ProgressBar>(R.id.progress)
val txvProgress = findViewById<TextView>(R.id.txvProgress)
val img = findViewById<AppCompatImageView>(R.id.img)
val animator = ObjectAnimator.ofInt(progress, "progress", 1, 100)
animator.apply {
duration = 2000
addUpdateListener { value ->
txvProgress.text = String.format(
getString(R.string.label_n_percent),
value.animatedValue.toString()
)
if (value.animatedValue == 100) {
img.invisibleWithFadeOutAnimation()
progress.visibility = View.GONE
txvProgress.visibility = View.GONE
value.cancel()
}
}
start()
}
}
private fun View.invisibleWithFadeOutAnimation() {
this.startAnimation(AnimationUtils.loadAnimation(this@MainActivity, R.anim.fade_out))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment