FragmentManager正确实例化片段,但内容片段不可见

时间:2020-06-10 10:13:55

标签: android android-fragments

一段时间以来,我一直在尝试解决此问题。我的应用程序使用了slidePaneLayout来显示其中的片段。我的问题是低于28的API,在将片段加载到slidePaneLayout上一段时间后,实例化新片段时,它们的内容部分或完全不可见,但片段本身正常工作(即使内容不可见,声音和计时器也可以正常工作)应用程式的背景,然后重新显示片段的内容,没有任何问题。 我不知道到底是什么原因造成的,如果有人以前曾遇到过此问题并有迹象表明这对我有很大帮助。

对于slidePaneLayout,我使用以下库: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()
}

应该是什么样子

enter image description here

此问题首次出现时会发生什么情况

image first error

首次发行后,所有片段加载的内容都不可见(橙色箭头来自活动视图)

[{image errors after first error 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
   }
}

片段视图正确显示,我不知道为什么

0 个答案:

没有答案