片段开始时如何运行约束动画?如果我将applyTo()
方法添加到ViewCreated
或onActivityCreated
时它不显示动画,因为当布局出现在屏幕上时它就完成了,唯一想到的解决方案是设置动画开始之前的延迟5s,然后从onResume()
开始。
动画方法:
private fun animateEntry(){
val layoutStart = ConstraintSet().clone(main_layout)
val layoutEnd = ConstraintSet()
layoutEnd.clone(context, R.layout.fragment_launch_end)
TransitionManager.beginDelayedTransition(main_layout)
layoutEnd.applyTo(main_layout)
}
我要从以下位置运行此方法的地方
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setupButtons()
//animateEntry()
}
override fun onResume() {
super.onResume()
//animateEntry()
}
override fun onStart() {
super.onStart()
//animateEntry()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
animateEntry()
}