CoordinatorLayout.Behavior 未被调用

CoordinatorLayout.Behavior not being called

我正在尝试按照 here

中所述在自定义 FAB 菜单上实施协调器布局行为

程序编译并运行,但从未调用协调器布局行为函数,因此 SnackBar 覆盖了 FAB 菜单。

关于 SO 的唯一其他问题是 here 但提供的解决方案不是我的问题。

这里是 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>

这是我的 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;
  }
}

没有错误,snackbar 显示,它只是覆盖了 FAB 菜单...我似乎无法弄清楚错误在哪里。

要让快餐店推送 FAB,您需要在制作时将 FloatingActionsMenu 视图传递给快餐店。

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

然后调用show()方法。这应该可以解决问题