3

我从 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>
4

1 回答 1

3

这似乎是BottomAppBar. FAB 的垂直偏移量取决于 BottomAppBar 的高度;如果您设置layout_height48dp相反,它将很好地坐在摇篮中。另一方面,如果将高度设置为 be 200dp,您会看到 FAB 更远。

此外(不幸的是),app:fabCradleVerticalOffset必须是一个正值。如果您尝试使用负值(将 FAB 向下推),应用程序将在运行时崩溃。

我没有看到任何可以让您解决此问题的公共 API。相反,您只需为BottomAppBar. 也许您可以将两个视图拼接在一起以模拟更高的条形图。

于 2019-01-04T19:22:05.820 回答