【问题标题】:How to prevent FAB overlaying BottomSheet when Expanded?展开时如何防止FAB覆盖BottomSheet?
【发布时间】:2021-05-12 13:53:55
【问题描述】:

我在我的 Android 应用程序中使用 Material FAB 和 BottomSheet,我遇到了覆盖 BottomSheet 的 FAB 的一些问题,我会阻止它。

实际上,当 BottomSheet1 完全展开时,我有两个 BottomSheet >

我还试图让 BottomSheet 海拔高于 FAB 海拔,但它没有任何作用。

我的代码如下所示:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    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"
    tools:context=".LetturaActivity">

        <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        style="@style/Widget.MaterialComponents.BottomAppBar.Colored"
        android:layout_gravity="bottom"
        app:navigationIcon="@drawable/ic_baseline_menu_24"
        app:menu="@menu/bottom_app_bar"
        app:hideOnScroll="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" \>
   
    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fabNuovo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_add"
        android:elevation="4dp"
        app:tint="@color/white"
        android:contentDescription="@string/nuovo_documento"
        app:layout_anchor="@id/bottomAppBar"
        />


    <include layout="@layout/bottom_sheet_testata" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

BottomSheet 父布局如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottomSheetTestata"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    app:behavior_hideable="true"
    android:elevation="5dp"
    android:clickable="false"
    android:focusable="false"
    app:behavior_peekHeight="0dp"
    app:layout_behavior="@string/bottom_sheet_behavior"
    android:orientation="vertical">

   ...

<\LinearLayout>

但是BottomSheet展开后是这样的:

【问题讨论】:

    标签: android kotlin floating-action-button bottom-sheet


    【解决方案1】:

    不是重叠就是重叠,问题是高程。

    documentation 你可以看到所有元素都有不同的高度。

    Fab 是6dp,虽然BottomSheet 在那里不容易找到,但应该是16dp(您可以使用浏览器功能输入关键字bottom

    所以把你的海拔改为

    android:elevation="16dp"
    

    【讨论】:

    • bottomSheetTestataelevation 5 更改为 16 并且按预期工作,只是将重叠更改为覆盖 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 2021-02-08
    • 2014-05-19
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多