我想两个一起开始两个动画。
第一个动画是交易动画
val transaction = supportFragmentManager.beginTransaction()
transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right)
transaction.replace(R.id.container, fragment, fragment::javaClass.name)
transaction.addToBackStack(fragment::javaClass.name)
transaction.commit()
第二个动画是活动中的搜索栏动画
abstract class BaseProgressFragment : BaseFragment() {
abstract val progressCount: Int
abstract val seekBar: NonEnabledSeekBar
abstract val tvProgress: TextView
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
animateProgress()
}
private fun animateProgress() {
val progress = "$progressCount%"
val progressAnimator = ObjectAnimator.ofInt(seekBar, "progress", seekBar.progress, progressCount * 100)
progressAnimator.duration = 600
progressAnimator.interpolator = LinearInterpolator()
progressAnimator.start()
seekBar.progress = progressCount * 100
tvProgress.text = progress
}}
在子片段中
override val seekBar: NonEnabledSeekBar
get() = (activity as CreateOrderActivity).sbCreatingOrder
当我仅启动1个动画就可以了,但是当我尝试启动它们时,它们会一起冻结UI。
请告诉我如何解决这个问题。
答案 0 :(得分:0)
我可以解决
seekBar.setLayerType(View.LAYER_TYPE_HARDWARE, null)
和
val progressAnimator = ObjectAnimator.ofInt(seekBar, "progress", seekBar.progress, progressCount * 100)
progressAnimator.duration = 600
progressAnimator.interpolator = LinearInterpolator()
progressAnimator.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
seekBar.setLayerType(View.LAYER_TYPE_NONE, null)
}
})
progressAnimator.start()