【问题标题】:FloatingActionButton too high over BottomAppBarFloatingActionButton 高于 BottomAppBar
【发布时间】:2019-01-04 18:30:15
【问题描述】:

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

【问题讨论】:

    标签: android android-layout floating-action-button android-bottomappbar


    【解决方案1】:

    这似乎是BottomAppBar 的一个错误(或者可能是一个功能)。 FAB 的垂直偏移量取决于 BottomAppBar 的高度;如果您将layout_height 设置为48dp,它会很好地放置在摇篮中。另一方面,如果您将高度设置为200dp,您会看到FAB 更远。

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

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

    【讨论】:

    • 哇,谢谢。我会认为这是一个错误。我能够使用正常的应用栏高度和底部的边距(和白色背景)来修复它。
    猜你喜欢
    • 2021-02-09
    • 2018-11-04
    • 2021-12-14
    • 1970-01-01
    • 2021-06-17
    • 2020-09-18
    • 1970-01-01
    • 2018-12-03
    • 1970-01-01
    相关资源
    最近更新 更多