Android 在DialogFragment上我的布局外放置一个按钮

Android 在DialogFragment上我的布局外放置一个按钮,android,layout,modal-dialog,Android,Layout,Modal Dialog,首先,看一下这张照片: 我想在此模式中放置一个关闭按钮,如下所示: 但我想不出怎么做,下面是我的布局文件: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"

首先,看一下这张照片:

我想在此模式中放置一个关闭按钮,如下所示:

但我想不出怎么做,下面是我的布局文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="br.com.makadu.makaduevento.ui.fragments.wizardInteligenceArtificial.WizardAIFifthStep">


<android.support.constraint.ConstraintLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv_title_subjects_schedule_suggestion"
        android:paddingTop="@dimen/screen_title_top_bot_padding"
        android:paddingBottom="@dimen/screen_title_top_bot_padding"
        android:background="@color/Verde2"
        android:gravity="center_horizontal"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:textSize="@dimen/txt_medium"
        android:text="@string/str_screen_title_subjects"
        tools:layout_constraintTop_creator="1"
        tools:layout_constraintRight_creator="1"
        app:layout_constraintRight_toRightOf="parent"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:text="@string/str_according_to_your_interests_title"
        style="@style/Theme.DefaultTextView.PrimaryDark.Bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toLeftOf="parent"
        android:id="@+id/tv_according_interests"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/tv_title_subjects_schedule_suggestion" />


    <ExpandableListView
        android:id="@+id/elv_suggested_schedule"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/tv_according_interests"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/b_confirm_schedule">


    </ExpandableListView>



    <Button
        android:id="@+id/b_confirm_schedule"
        style="@style/Theme.DefaultButton.Purple.Radius"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="@string/str_confirm_schedule_button"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginBottom="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginEnd="8dp" />

</android.support.constraint.ConstraintLayout>

提前谢谢。
stackoverflow要求我更好地解释我的问题,但我猜图片本身就解释了,所以我现在只写一些没有意义的文本。

第一个解决方案,它将100%有效,但我认为不漂亮:
您可以使根布局透明,并将其放入所需的可见视图中。您可以将根视图的
OnClickListener
设置为在点击可见视图时隐藏对话框。
第二个解决方案,可能会起作用,我现在无法检查:
您可以关闭根视图的
clipPadding
,并将关闭按钮移到不可见的位置。

另外,我是从手机上写的,所以它没有很好的视图格式,也没有示例。

我也遇到过类似的问题,你应该创建一个带有重心和背景透明的边距的线性布局,添加一个与对话框内容相对应的窗口

在RelativeLayout中,你可以使用android:layout\u alignParentRight=“true”&android:layout\u alignParentTop=“true”
作为包含关闭按钮的图像视图(可能你也需要使用一些边距),因此它将显示在包含对话框标题的文本视图上方

我希望这对你有帮助,明天我会给你发一个代码