android - 如果没有活动的第一个片段中的处理程序,动画将无法工作
问题描述
我在正常状态下不起作用的片段中使用了动画。我应该在 handlers 中使用它们。我正在使用片段导航,这是出现此问题的活动的第一个片段。其他片段工作正常。
class HomeFragment : BaseFragment<FragmentHomeBinding>() {
override fun onResume() {
super.onResume()
if (firstTime) {
Handler().postDelayed({
binding.finalHomeFragment.setTransitionDuration(1)
binding.finalHomeFragment.transitionToEnd()
binding.view.visibility = View.GONE
binding.buttonLayout.visibility = View.GONE
setTransition()
}, 0)
firstTime = false
} else {
Handler().postDelayed({
binding.finalHomeFragment.setTransitionDuration(1500)
binding.finalHomeFragment.transitionToEnd()
}, 0)
}
private fun setTransition() {
val autoTransition = AutoTransition()
autoTransition.duration = 500
TransitionManager.beginDelayedTransition(binding.container,
autoTransition)
val set = ConstraintSet()
set.clone(binding.container)
set.setVisibility(binding.buttonLayout.id, View.VISIBLE)
set.setVisibility(binding.view.id, View.VISIBLE)
set.applyTo(binding.container)
}
}
我使用 MotionLayout 和 TransitionManager 制作动画
解决方案
推荐阅读
- java - 如何创建kafka监听器并在spring上下文中动态添加它们
- javascript - 如何在 chrome 扩展中添加额外的 javascript
- html - 在 CSS @each 循环中逐渐增加 15 秒的时间
- qt - 在模型和视图之间使用包装器时,QTreeView 不显示任何项目
- android - 在 kotlin 中解析 volley 响应时出错
- clojure - clj-http 返回状态 200 但 cljs-http 客户端为同一请求返回状态 0
- vb.net - 允许将 Timespan 数据输入到 Access 数据库字段
- json - 访问 JSON 树中的数据
- laravel - Laravel Airlock 如何为未经身份验证的 Web 和 api 请求返回不同的响应
- ecmascript-6 - ()=>async()=>{} 是什么意思?