Анимация не воспроизводится в то же время, когда я устанавливаю несколько ObjectAnimator
с playTgether()
на уровне API 23, но она работает так, как я ожидал выше уровня API 24.
Однако, когда я устанавливаю каждыйObjectAnimator
с play()
анимация работает так, как я ожидал, для API-интерфейса эмулятора 23 и 24.
Может кто-нибудь посоветовать мне причину проблемы?
Я прикреплю GIF и следующий код.
Анимации
В эмуляторе уровня 23 API
api_23.gif:
В эмуляторе уровня 24 API
api_24.gif:
Код
activity_text.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.view.activity.TestActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/browser_actions_title_color" />
</RelativeLayout>
TestActivity.kt
class TestActivity: AppCompatActivity() {
private val TRANSLATION_X_START = 0f
private val TRANSLATION_X_END = 500f
private val TRANSLATION_Y_START = 0f
private val TRANSLATION_Y_END = 500f
private val DELAY_TRANSLATION = 2000
private val TRANSLATE_ANIMATION_TIME = 800
private val DEFAULT_SCALE = 1f
private val MAX_SCALE = 3f
private val DELAY_SCALE = 2000
private val SCALE_ANIMATION_TIME = 800
private val MIN_ALPHA = 0f
private val MAX_ALPHA = 255f
private val DELAY_ALPHA = 2250
private val ALPHA_ANIMATION_TIME = 800
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
startAnimation(imageView)
}
private fun startAnimation(view: View) {
val animationSet = AnimatorSet()
val animatorX = ObjectAnimator.ofFloat(view, "x", TRANSLATION_X_START, TRANSLATION_X_END)
animatorX.interpolator = AccelerateDecelerateInterpolator()
animatorX.duration = TRANSLATE_ANIMATION_TIME.toLong()
animatorX.startDelay = DELAY_TRANSLATION.toLong()
val animatorY = ObjectAnimator.ofFloat(view, "y", TRANSLATION_Y_START, TRANSLATION_Y_END)
animatorY.interpolator = AccelerateDecelerateInterpolator()
animatorY.duration = TRANSLATE_ANIMATION_TIME.toLong()
animatorY.startDelay = DELAY_TRANSLATION.toLong()
val animatorScaleX = ObjectAnimator.ofFloat(view, "scaleX", DEFAULT_SCALE, MAX_SCALE)
animatorScaleX.interpolator = LinearInterpolator()
animatorScaleX.duration = SCALE_ANIMATION_TIME.toLong()
animatorScaleX.startDelay = DELAY_SCALE.toLong()
val animatorScaleY = ObjectAnimator.ofFloat(view, "scaleY", DEFAULT_SCALE, MAX_SCALE)
animatorScaleY.interpolator = LinearInterpolator()
animatorScaleY.duration = SCALE_ANIMATION_TIME.toLong()
animatorScaleY.startDelay = DELAY_SCALE.toLong()
val animatorAlpha = ObjectAnimator.ofFloat(view, "alpha", MAX_ALPHA, MIN_ALPHA)
animatorAlpha.interpolator = LinearInterpolator()
animatorAlpha.duration = ALPHA_ANIMATION_TIME.toLong()
animatorAlpha.startDelay = DELAY_ALPHA.toLong()
animationSet.playTogether(animatorX, animatorScaleX, animatorY, animatorScaleY, animatorAlpha)
animationSet.addListener(object : Animator.AnimatorListener {
override fun onAnimationEnd(animation: Animator) {
}
override fun onAnimationStart(animation: Animator) {
}
override fun onAnimationCancel(animation: Animator) {}
override fun onAnimationRepeat(animation: Animator) {}
})
animationSet.start()
}
}
Код хорошо работает как для api23, так и дляapi24
animationSet.play(animatorX)
animationSet.play(animatorScaleX)
animationSet.play(animatorY)
animationSet.play(animatorScaleY)
animationSet.play(animatorAlpha)