Search code examples
androidandroid-layoutandroid-fragmentsandroid-viewandroid-dialogfragment

Layout stretching when dismissing DialogFragment


I have an Activity that has the following layout:

<?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>

The add_item_btn has an event on click that creates a full-screen (edited to add this information) DialogFragment to insert the item information and add it to local database. The following code shows how I create the 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();

The problem is that when I dismiss() the created fragment, the activity layout stretches, in a way that the BottomBar goes half behind the on-screen button bar (see images).

enter image description here enter image description here

I tried changing the FragmentTransaction (from android.R.id.content to R.id.main_content, when main_content was the id of the root RelativeLayout) with no success. I also tried using 2 different implementations of the Material Design Bottom Navigation Bar, but both had the same behaviour.


Solution

  • Found the answer! I don't actually know why, since I have almost no experience with CoordinatorLayout, but switching the root Layout of the FragmentDialog to LinearLayout solved the problem.