首页 > 解决方案 > Android 我的底部应用程序栏与我的回收站视图重叠

问题描述

我正在尝试解决我的 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>

当我填写清单时,我无法到达回收站视图中的最后一项。我尝试添加边距,但没有奏效。

在此处输入图像描述

标签: androidandroid-layoutkotlinandroid-fragmentsandroid-mvvm

解决方案


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

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

推荐阅读