延迟文本更改,直到动画在android中完成



我希望这个animation在新文本出现之前完成。当前,新文本出现在animation开始之前。关于如何delay文本更改,有什么想法吗?

这是animation xml文件:

<?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>

这是我的代码:

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

您是否尝试过使用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?) {
}
})

最新更新