2

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.

Community
  • 1
  • 1
easycheese
  • 5,859
  • 10
  • 53
  • 87
  • This has the answer to your question: http://stackoverflow.com/questions/32802886/move-cardview-on-snackbar-co-ordinator-layout – android_eng Dec 29 '15 at 18:30
  • @Rohit_Ramkumar I reviewed the answers in that question and found nothing useful. Perhaps you could explain what I missed? – easycheese Dec 29 '15 at 18:35
  • Alright. Can you post the code when you display the snackbar. I want to see how you make the snackbar and display it. – android_eng Dec 29 '15 at 18:40

1 Answers1

3

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

android_eng
  • 1,370
  • 3
  • 17
  • 40
  • Yes, that was it. I had it being called in a Fragment using getView(). I found it separately here: https://guides.codepath.com/android/Displaying-the-Snackbar but I'll give you the win :) – easycheese Dec 29 '15 at 19:16