Last active
June 18, 2022 17:42
-
-
Save siscofran999/e0a73dc7db26b2e06f822751510abfea to your computer and use it in GitHub Desktop.
This file contains 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
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