Home > Blockchain >  Delaying text change until animation completes in android
Delaying text change until animation completes in android

Time:10-15

I want this animation to be complete before the new text appears. Currently, the new text appears before the animation begins. Any ideas on how to delay the text change?

This is the animation xml file:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromXDelta="0" android:toXDelta="-100%p"
        android:duration="@android:integer/config_mediumAnimTime"/>
</set>

And here is my code:

fun slideLeft(){questionText.startAnimation(AnimationUtils.loadAnimation(context, R.anim.slide_out_left)) questionText.text = "New Text coming here"}

CodePudding user response:

Have you tried working around AnimationListener ?

 textView.animation.setAnimationListener(object: Animation.AnimationListener{
            override fun onAnimationStart(p0: Animation?) {
                  // do something before animation
            }

            override fun onAnimationEnd(p0: Animation?) {
                 // do something after animation
            }

            override fun onAnimationRepeat(p0: Animation?) {
            }
     })
  • Related