解除DialogFragment时的布局拉伸

Min*_*oru 8 android android-layout android-fragments android-view android-dialogfragment

我有一个具有以下布局的Activity:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/top_menu_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="16dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        // ICONS

    </RelativeLayout>

    <FrameLayout
        android:id="@+id/temperatura_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="184dp"
        android:layout_centerHorizontal="true">

        <com.github.pavlospt.CircleView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/reading_value"
            android:layout_width="192dp"
            android:layout_height="192dp"
            android:layout_gravity="center"
            />
    </FrameLayout>

    <ImageView
        android:id="@+id/add_item_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bottomBar"
        android:layout_centerHorizontal="true"
        android:padding="12dp"
        android:layout_marginTop="36dp"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:clickable="true"
        android:focusable="true"
        android:scaleType="center"
        app:srcCompat="@drawable/ic_add_item_black_24px"
        android:contentDescription="@string/add_item_btn_description" />

    <com.roughike.bottombar.BottomBar
        android:id="@+id/bottomBar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        app:bb_behavior="iconsOnly"
        app:bb_tabXmlResource="@xml/bottom_navbar" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

add_item_btn对点击创建一个事件全屏幕 (编辑添加此信息) DialogFragment插入的项目信息,并把它添加到本地数据库.以下代码显示了我如何创建DialogFragment:

FragmentManager fragmentManager = getSupportFragmentManager();
InsertItemDialogFragment fragment = new InsertItemDialogFragment();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.add(android.R.id.content, fragment).addToBackStack(null).commit();
Run Code Online (Sandbox Code Playgroud)

问题在于,当我dismiss()创建片段时,活动布局会延伸,其方式是BottomBar屏幕按钮栏后面的一半(参见图像).

在此输入图像描述 在此输入图像描述

我尝试改变FragmentTransaction(从,android.R.id.contentR.id.main_content,当时main_content是根的id RelativeLayout)没有成功.我还尝试使用Material Design Bottom Navigation Bar的两种不同实现,但两者都具有相同的行为.

Min*_*oru 1

找到答案了!我实际上不知道为什么,因为我几乎没有使用 的经验CoordinatorLayout,但是切换 的根布局FragmentDialogLinearLayout解决问题。