Android全屏DialogFragment生成了递归渲染的视图

时间:2019-05-15 11:15:13

标签: android fullscreen dialogfragment

我正在尝试创建全屏DialogFragment的抽象类, 奇怪的是结果看起来像这样:

enter image description here

但是它应该和

一样简单

enter image description here

似乎布局项以递归方式在其中一个容器中生成。

这发生在我的Android 7.0,API 24, 但在Android 9,API 28上看起来不错(不是很好)

(这些项目与原产地完全重叠。因此看起来不错。 如果在recyclerview上滚动某些内容,我会看到错误的内容)

如果我重建项目,此问题将以某种方式消失 但是有时候,不管我清理项目多少次,它总是存在的。这很令人困惑。

请帮助

抽象dialogfragment类的核心部分是

// dialogs are created from activity with 
class SomeActivity: FragmentActivity {
    ...
    fun showDialog(dialog: DialogFragment) {
        dialog.show(supportFragmentManager, "DIALOG")
    }
    ...
}

class SetHashTagDialogFragment: BaseFullScreenDialogFragment() {
    //the layout doesn`t matter anyway, I changed it to any layout else and it is still a mess
    override fun getLayoutId(): Int = R.layout.some_layout
}

abstract class BaseFullScreenDialogFragment: DialogFragment() {
    abstract fun getLayoutId(): Int

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(DialogFragment.STYLE_NORMAL, R.style.FullScreenDialogStyle)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        //nothing changed if I changed to this or not
        //return inflater.inflate(getLayoutId(), container, false)
        return activity?.layoutInflater?.inflate(getLayoutId(), container, false)
    }

    override fun onStart() {
        super.onStart()
        val width = ViewGroup.LayoutParams.MATCH_PARENT
        val height = ViewGroup.LayoutParams.MATCH_PARENT
        dialog?.window?.setLayout(width, height)
    }
}

//styles
<resources>
    <style name="FullScreenDialogStyle" parent="android:Theme.Holo.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="android:windowBackground">@null</item>
    </style>
</resources>

检查器的视图层次结构: enter image description here

这些是我拥有的大多数代码: https://gist.github.com/CyberRay/19efb6ee31262d202a32fcc0e162a061

0 个答案:

没有答案