Fug*_*ugo 5 android android-fragments kotlin android-transitions
我有一个片段,可以加载大量数据并将其显示到 recyclerView 中。如果我直接打开此片段而不等待转换完成,则转换将变得不稳定,因为线程受到 recyclerView 更新数据的限制
所以我想延迟这个更新数据,直到片段转换完成。
但遗憾的是,我还没有找到任何方法来监听片段转换完成,因此我当前的方法是将数据更新延迟几毫秒,直到使用 Handler() ,但我相信这是非常hacky并且不是优雅的解决方案
Handler().postDelayed({
//do something
}, 500)
Run Code Online (Sandbox Code Playgroud)
我需要帮助来知道应该调用什么方法来监听片段转换完成。谢谢你uu
嗯,我按照这个答案以某种方式使用 onCreateAnimation 做到了这一点
override fun onCreateAnimation(transit: Int, enter: Boolean, nextAnim: Int): Animation? {
val anim: Animation = AnimationUtils.loadAnimation(activity, nextAnim)
anim.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation?) {}
override fun onAnimationRepeat(animation: Animation?) {}
override fun onAnimationEnd(animation: Animation?) {
if (enter) {
//load and update recyclerView here
}
}
})
return anim
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1774 次 |
| 最近记录: |