Android 我的底部应用程序栏与我的回收视图重叠

Android my bottom app a bar is overlapping my recyclerview

我正在尝试解决我的 recyclerview 与 bottomappbar 重叠的问题。这是我的布局代码。

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/notes_container_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
     >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:padding="8dp"
            android:text="@string/myTasksHeader"
            android:textColor="@color/appBarTextColor"
            android:textSize="40dp" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:padding="16dp"
                android:scrollbars="none"
                tools:listitem="@layout/note_list_item" />
        </ScrollView>

    </LinearLayout>

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:backgroundTint="@color/colorPrimary"
        app:hideOnScroll="false"
        app:menu="@menu/appbar_menu"
        app:navigationIcon="@drawable/ic_menu" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/add_note_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/medium_margin"
        android:backgroundTint="@color/colorPrimary"
        app:layout_anchor="@id/bottomAppBar"
        app:srcCompat="@drawable/ic_add_black_24dp"
        tools:ignore="VectorDrawableCompat" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

当我填满我的列表时,我无法在回收站视图中找到我的最后一项。我尝试添加边距,但没有用。

两种实现方式

  1. 滚动时隐藏BottomAppBar布局..

    BottomAppBar

    中添加以下属性
            app:fabAlignmentMode="center"
            app:fabCradleMargin="10dp"
            app:fabCradleRoundedCornerRadius="10dp"
            app:hideOnScroll="true"
    
  2. 如果你不想隐藏 BottomAppBar 那么从底部添加边距 在 RecyclerView

    android:layout_marginBottom="?actionBarSize"
    

使用边距的问题是 RecyclerView 不会通过 FAB 显示。比使用边距更好的解决方案是使用填充在 RecyclerView 的底部添加额外的 space。

android:clipToPadding="false"
android:paddingBottom="?actionBarSize"