我在我的应用中使用视图动画。这是动画文件
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="1500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toXScale="7.0"
android:toYScale="7.0"
/>
<alpha
android:duration="600"
android:fromAlpha="1.0"
android:repeatCount="infinite"
android:startOffset="900"
android:toAlpha="0.0" />
</set>
以下是用于在视图上设置动画的kotlin代码。
val connectingAnimationWave1 = AnimationUtils.loadAnimation(activity, R.anim.anim_otp_wave_1)
connectingAnimationWave1.repeatCount = Animation.INFINITE
connectingAnimationWave1.repeatMode = Animation.INFINITE
connectingAnimationWave1.setAnimationListener(object : Animation.AnimationListener{
override fun onAnimationRepeat(p0: Animation?) {
Log.d("MyAnimListener", "Repeat "+ p0!!.startOffset)
}
override fun onAnimationEnd(p0: Animation?) {
Log.d("MyAnimListener", "End "+ p0!!.startOffset)
}
override fun onAnimationStart(p0: Animation?) {
Log.d("MyAnimListener", "Start "+ p0!!.startOffset)
}
})
view_wave_1.animation = (connectingAnimationWave1)
问题在于我没有得到onAnimationRepeat()
永远不会被调用。只有onAnimationStart()
被调用。此外,如果我运行一个线程5秒然后清除动画,那么onAnimationEnd()
也会被调用。永远不会调用onAnimationRepeat()
。