Search code examples
androidfloating-action-buttonandroid-appbarlayout

AppBar Layout overlaping floating action button after transition


I've issue: On my main activity i launched other activity with floating action button. In intent I sent shared element transition. Everything is good, except that AppBar overlap Fab. It seems that AppBar behavior was changed. Please tell me where to seek?

part of main activity, where shared element transition is initialized:

 case R.id.start_page_fab:
                intent = AddTransactionActivity.newIntent(this, CATEGORY_LIST);
                Pair<View, String> p1 = Pair.create(findViewById(R.id.appcollapse), "start_page_transition");
                Pair<View, String> p4 = Pair.create(findViewById(R.id.start_credit_card), "start_page_transition");
                Pair<View, String> p2 = Pair.create(findViewById(R.id.start_page_fab),"start_page_transition");
                ActivityOptionsCompat options = ActivityOptionsCompat
                        .makeSceneTransitionAnimation(this,p1,p4,p2);
                startActivity(intent,options.toBundle());
                break;

method setupEnterAnimation in other activity, whitch intercepts transition:

private void setupEnterAnimation() {
        Transition transition = TransitionInflater.from(getContext()).inflateTransition(R.transition.start_page_trancition);
        transition.setDuration(500);
        getActivity().getWindow().setSharedElementEnterTransition(transition);
    }

part of layout with AppBar

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/start_layout"
    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="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="ru.berezin.maxim.im.budget_v3.userinterface.StartPage">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appcollapse"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:transitionName="start_page_transition">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main_collapsing"
            android:layout_width="match_parent"
            android:layout_height="280dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            >

            <com.github.mikephil.charting.charts.PieChart
                android:id="@+id/start_chart"
                android:layout_width="match_parent"
                android:layout_height="260dp"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="1.3"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
...

And another layout:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/add_tran_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appcollapse"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:transitionName="start_page_transition">

        <Switch
            android:id="@+id/transaction_switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:paddingEnd="16dp"
            android:paddingStart="16dp"
            android:paddingTop="16dp"
            android:text="@string/credit"
            />

        <android.support.design.widget.TextInputLayout
            android:id="@+id/transaction_photo_sum_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingEnd="16dp"
            android:paddingStart="16dp"
            >

            <EditText
                android:id="@+id/transaction_sum"
                android:layout_width="285dp"
                android:layout_height="wrap_content"
                android:hint="@string/transaction_sum_hint"
                android:inputType="numberDecimal"
                android:maxLength="10"
                android:textSize="34sp"/>
        </android.support.design.widget.TextInputLayout>
    </android.support.design.widget.AppBarLayout>
.....

Solution

  • Ok, I fixed it. For some strange reason if I anchor floating button to appbar, when, after transition, it's overlapped it. So I added collapsing toolbar and anchored fab to it.