Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snackbar not moving FAB that placed inside Fragment

There is a scheme that describes view hierarchy of my application.

Example

And some XML

MainActivity

. CoordinatorLayout
  . FrameLayout <- ContentFragment inserted here
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
  . AppBarLayout
    . Toolbar

ContentFragment

<FrameLayout
    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.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:src="@drawable/ic_plus_white_36dp"
        android:layout_gravity="bottom|end"
        android:layout_margin="15dp"
        app:elevation="6dp"
        app:pressedTranslationZ="12dp"/>

    <TextView
        android:id="@+id/hint_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/empty_dates_list"
        android:padding="20dp"
        android:textSize="20sp"
        android:layout_gravity="center" />

</FrameLayout>

With this code I make SnackBar:

Snackbar snackbar = Snackbar.make(
        mainActivity.getCoordinatorLayout(),
        R.string.date_removed,
        Snackbar.LENGTH_LONG);

My problem is that fab is not moving up by SnackBar that I make in ContentFragment

I also tried point fab as view for Snackbar but it has not brought results.

like image 518
Alexandr Avatar asked Jan 26 '16 13:01

Alexandr


2 Answers

You should use CoordinatorLayout to avoid this issue because CoordinatorLayout alone properly coordinates layout changes caused by its child views.

To solve your issue, simply move the FloatingActionButton from the fragment layout to the MainActivity layout. Or if you intend to use the FloatingActionButton in the fragment itself, then set the parent view of the fragment to be a CoordinatorLayout

like image 123
TeChNo_DeViL Avatar answered Nov 14 '22 08:11

TeChNo_DeViL


For this to work, FloatingActionButton should be a child of CoordinatorLayout. Yours is a child of FrameLayout.

like image 36
poss Avatar answered Nov 14 '22 06:11

poss