FloatingActionButton 比 BottomAppBar 高
FloatingActionButton too high over BottomAppBar
我从 API 28 向 BottomAppBar 添加了一个 FAB,如下面的 XML 所示。问题是它漂浮在底栏上方太高而不是坐在摇篮中。如果我将 app:fabCradleVerticalOffset 设置为 0dp,则没有任何变化。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:paddingTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
app:backgroundTint="@android:color/white"
app:fabAlignmentMode="center" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabIncrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_exposure_plus_1_black_24dp"
app:backgroundTint="@color/colorPrimary"
app:fabSize="normal"
app:layout_anchor="@id/bottomAppBar" />
</android.support.design.widget.CoordinatorLayout>
这似乎是 BottomAppBar
的一个错误(或者可能是一个功能)。 FAB 的垂直偏移量取决于 BottomAppBar 的高度;如果您将 layout_height
设置为 48dp
,它将非常适合放在摇篮中。另一方面,如果您将高度设置为 200dp
,您会发现 FAB 距离更远。
此外(不幸的是),app:fabCradleVerticalOffset
必须是正值。如果您尝试使用负值(将 FAB 向下推),应用程序将在运行时崩溃。
我没有看到任何 public API 可以让您解决这个问题。相反,您只需为 BottomAppBar
使用较小的高度。或许您可以将两个视图拼接在一起以模拟更高的条形。
我从 API 28 向 BottomAppBar 添加了一个 FAB,如下面的 XML 所示。问题是它漂浮在底栏上方太高而不是坐在摇篮中。如果我将 app:fabCradleVerticalOffset 设置为 0dp,则没有任何变化。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:paddingTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="bottom"
app:backgroundTint="@android:color/white"
app:fabAlignmentMode="center" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabIncrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_exposure_plus_1_black_24dp"
app:backgroundTint="@color/colorPrimary"
app:fabSize="normal"
app:layout_anchor="@id/bottomAppBar" />
</android.support.design.widget.CoordinatorLayout>
这似乎是 BottomAppBar
的一个错误(或者可能是一个功能)。 FAB 的垂直偏移量取决于 BottomAppBar 的高度;如果您将 layout_height
设置为 48dp
,它将非常适合放在摇篮中。另一方面,如果您将高度设置为 200dp
,您会发现 FAB 距离更远。
此外(不幸的是),app:fabCradleVerticalOffset
必须是正值。如果您尝试使用负值(将 FAB 向下推),应用程序将在运行时崩溃。
我没有看到任何 public API 可以让您解决这个问题。相反,您只需为 BottomAppBar
使用较小的高度。或许您可以将两个视图拼接在一起以模拟更高的条形。