簡體   English   中英

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 向下推),應用程序將在運行時崩潰。

我沒有看到任何可以讓您解決此問題的公共 API。 相反,您只需為您的BottomAppBar使用較小的高度。 也許您可以將兩個視圖拼接在一起以模擬更高的條形圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM