android - FragmentManager 正确实例化片段,但内容片段不可见
问题描述
我一直在尝试解决这个问题一段时间。我的应用使用slidingPaneLayout 来显示其中的片段。我的问题是低于 28 的 API,在slidingPaneLayout 上加载片段一段时间后,当实例化新片段时,它们的内容变得部分或完全不可见,但片段本身可以正常工作(即使内容不可见,声音和计时器也可以工作),如果我去背景与应用程序并返回片段的内容重新出现没有任何问题。我不知道究竟是什么导致了这个问题,如果有人以前遇到过这个问题并且有一些迹象,那对我来说会有很大的帮助。
对于slidingPaneLayout,我使用这个库:https ://github.com/umano/AndroidSlidingUpPanel
为了改变我的片段,我使用这个:
fun showFragment(fragment: Fragment, containerId: Int, tag: String) {
val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.replace(containerId, fragment, tag)
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()
}
它应该是什么样子:
首次出现此问题时会发生什么
第一次发出后,所有片段都加载了不可见的内容(橙色箭头来自活动视图)
[ 3
PS:我用应用程序上的 canaryleak 纠正了几乎所有的内存泄漏
PS:我使用的是最新版本的 Fragments,androidx.fragment:fragment:1.2.4
编辑:当我在我的片段中强制 onStop 时,如下所示:
var firstTime = true
override fun onResume() {
super.onResume()
if(firstTime){
onStop()
firstTime = false
}
}
片段视图正确显示我不知道为什么
解决方案
推荐阅读
- django - 过滤时如何在django中同时使用AND或OR条件
- django - 在 django 中扩展管理界面
- laravel - 如何最大限度地减少获取位置详细信息的运行时间?
- tcl - 如何使用 Critcl 设置参数指向的数据?
- python - 使用python将高程(XYZ)数据转换为坡度/梯度图
- php - regex: select all characters before and after a specific string
- javascript - 如何突出显示字符串中的文本?
- r - 如何比较两个数据框的内容?
- pandas - 在 Pandas 中部分透视表
- regex - 如何在 Jmeter 中定义正则表达式?