我的布局中有两个 FloatingActionButton。两者都以相同的方式附加到 CoordinatorLayout。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawerLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
[ appbar, toolbar, content... ]
<android.support.design.widget.FloatingActionButton
android:id="@+id/anon_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="88dp"
android:layout_marginRight="@dimen/fab_margin"
android:clickable="true"
android:onClick="onFabClick"
android:src="@drawable/ic_cloud_upload_white_24dp"
android:tint="?colorAccent"
app:backgroundTint="@color/tint_inverted_fab"
app:borderWidth="0dp"
app:layout_anchor="@id/coordinatorLayout"
app:layout_anchorGravity="bottom|end"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/keyboard_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:clickable="true"
android:onClick="onFabClick"
android:src="@drawable/ic_keyboard_white_24dp"
app:borderWidth="0dp"
app:layout_anchor="@id/coordinatorLayout"
app:layout_anchorGravity="bottom|end"
/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>
但是,当我显示一个小吃店时,只有底部的 FAB 上下移动。
Snackbar.make(mCoordinator, "FAB pressed", Snackbar.LENGTH_LONG).show();
如何让两者都动起来?