我有一个MainConstraintLayout和一个ViewPager。我想几乎同时实现两个动画。首先,ViewPager将通过ConstraintSet动画向下滑动。稍有延迟后,ViewPager中的某些项目将通过ConstraintSet动画滑动。
一个ViewPager按钮触发activeAnimation2()
private fun activateAnimation2() {
var animDur = 1000L
if (!areAnimationsEnabled) {
animDur = 0L
}
mainCSAnimation(500)
Handler().postDelayed({vpCSAnimation(1000)}, 400)
Handler().postDelayed({mainCSCircularIntroAnimation(1000)}, 600)
initializeActiveSessionActivity()
backgroundCalculationHandler.post(updateHistoryRecylcerViewLoop)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
tauIntroCard.elevation = 10f
tauViewPager.elevation = 11f
}
if (wantToSeeHelper) mHandler.postDelayed({ startSecondTrainer() }, 3000)
}
private fun mainCSAnimation(animDur: Long){
val mainCS = ConstraintSet()
mainCS.clone(tauMainConstLay)
val transition = ChangeBounds().apply {
duration = animDur
interpolator = LinearOutSlowInInterpolator()
}
TransitionManager.beginDelayedTransition(tauMainConstLay, transition)
if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
mainCS.connect(tauViewPager.id, ConstraintSet.TOP, tauHistoryRVBottomDivider!!.id, ConstraintSet.BOTTOM)
}
mainCS.setVerticalBias(tauViewPager.id, 0f)
mainCS.applyTo(tauMainConstLay)
}
private fun vpCSAnimation(animDur: Long) {
val vpCS = ConstraintSet()
vpCS.clone(msaConstraintLayout)
val transition = ChangeBounds().apply {
interpolator = AnticipateInterpolator()
duration = animDur
}
TransitionManager.beginDelayedTransition(msaConstraintLayout, transition)
vpCS.setHorizontalBias(addQuestionImg.id, .65f)
vpCS.setHorizontalBias(rewinsImg.id, .35f)
vpCS.setHorizontalBias(msaLeftEar.id, 0f)
vpCS.setHorizontalBias(msaRightEar.id, 1f)
vpCS.applyTo(msaConstraintLayout)
}
但是当activeAnimation2()被触发时,mainCSAnimation动画可以正常运行,但是vpCSAnimation不会被动画。 vpCSAnimation立即显示动画的结尾。
如果我没记错的话,如果第一个动画尚未完成,并且无法显示第二个动画的结尾,则无法在TransitionManager中开始第二个动画。我可以实现我的目标吗?