首页 > 解决方案 > 如何将 DialogFragment 放在另一个 DialogFragment 上方/下方?

问题描述

我正在尝试在 Dialog 片段上方/下方显示一些内容,但我不希望这两个位于相同的 XML 布局上,因为其中一个 DialogFragment 比另一个更宽,如果它们在同一个 XML 上,它看起来只是奇怪的。所以我试图实现这样的目标: 图片

我在这里发现了这个问题:如何将一个 DialogFragment 提升到另一个之上?但我认为这不适用于我的用例。

标签: androidandroid-fragmentsandroid-dialogfragment

解决方案


这里不需要两个不同的对话框。只为一个对话框充气,里面有两张卡片。

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <com.google.android.material.card.MaterialCardView ... />

    <com.google.android.material.card.MaterialCardView ... />

</androidx.constraintlayout.widget.ConstraintLayout>

推荐阅读