我正试图在自定义FAB菜单上实现协调器布局行为,如这里所述
程序编译并运行,但协调器布局行为函数从未被调用,因此SnackBar覆盖FAB菜单。
关于这一点,唯一的其他问题是这里,但提供的解决方案不是我的问题。
以下是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课程:
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菜单.我似乎不知道错误在哪里。
发布于 2015-12-29 18:49:04
要让快餐店推动FAB,您需要在制作FAB时将FloatingActionsMenu视图传递给snackBar。
Snackbar.make(FloatingActionsMenuVIEWINSTANCEHERE, mErrorMessage, Snackbar.LENGTH_LONG);然后调用show()方法。这应该能解决这个问题
https://stackoverflow.com/questions/34516679
复制相似问题