easycheese
easycheese

Reputation: 5899

CoordinatorLayout.Behavior not being called

I'm trying to implement coordinator layout behavior on a custom FAB menu as described here

The program compiles and runs but the coordinator layout behavior functions are never called so the SnackBar overlays the FAB menu.

The only other question on SO about it is here but the solution provided is not my issue.

Here is the xml:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.getbase.floatingactionbutton.FloatingActionsMenu
        android:id="@+id/fab_host"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        app:layout_behavior="com.companionfree.quizinator.couple.shared.FloatingActionMenuBehavior"
        fab:fab_icon="@drawable/ic_add_white_24dp"
        fab:fab_addButtonColorNormal="@color/colorAccent">


        <com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab_host_bluetooth"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_colorNormal="@color/colorAccent"
            fab:fab_icon="@drawable/ic_bluetooth_white_24dp"/>


        <com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab_host_nearby"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_colorNormal="@color/colorAccent"
            fab:fab_icon="@drawable/ic_signal_wifi_4_bar_white_24dp"/>


    </com.getbase.floatingactionbutton.FloatingActionsMenu>
</android.support.design.widget.CoordinatorLayout>

And here is my CoordinatorLayout.Behavior class:

public class FloatingActionMenuBehavior extends CoordinatorLayout.Behavior<FloatingActionsMenu> {

  public FloatingActionMenuBehavior(Context context, AttributeSet attrs) {}

  @Override
  public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionsMenu child, View dependency) {
    return dependency instanceof Snackbar.SnackbarLayout;
  }

  @Override
  public boolean onDependentViewChanged(CoordinatorLayout parent, FloatingActionsMenu child, View dependency) {
      float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
    child.setTranslationY(translationY);
    return true;
  }
}

There are no errors, the snackbar displays, it just overlays the FAB menu...I can't seem to figure out where the error is.

Upvotes: 2

Views: 1588

Answers (1)

android_eng
android_eng

Reputation: 1370

For the snack bar to push the FAB you need to pass the FloatingActionsMenu view to the snackBar while making it.

 Snackbar.make(FloatingActionsMenuVIEWINSTANCEHERE, mErrorMessage, Snackbar.LENGTH_LONG);

and then call the show() method. This should fix the issue

Upvotes: 3

Related Questions