android上CoordinatorLayout中RecyclerView下方的底部视图

android上CoordinatorLayout中RecyclerView下方的底部视图,android,android-coordinatorlayout,android-snackbar,Android,Android Coordinatorlayout,Android Snackbar,我从ConstraintLayout切换到CoordinatorLayout,以避免snackbar与底部视图重叠。虽然它在只有工具栏、RecyclerView和浮动按钮的屏幕上工作得很好,但在第二个屏幕上,我很难在RecyclerView下方添加视图,同时避免与RecyclerView重叠 我的最佳解决方案(如下)是将about80dp的paddingBottom属性添加到recyclerView。这看起来解决了问题,但当snackbar打开时,底部视图android:id=“@+id/ite

我从ConstraintLayout切换到CoordinatorLayout,以避免snackbar与底部视图重叠。虽然它在只有工具栏、RecyclerView和浮动按钮的屏幕上工作得很好,但在第二个屏幕上,我很难在RecyclerView下方添加视图,同时避免与RecyclerView重叠

我的最佳解决方案(如下)是将about
80dp
paddingBottom
属性添加到recyclerView。这看起来解决了问题,但当snackbar打开时,底部视图
android:id=“@+id/item\u cl\u add”
将再次与recyclerView重叠。当然,我可以添加更多的
paddingBottom
来补偿snackbar的大小,但这意味着我将损失大约20dp的不动产(这不是一个好主意)

我查看了很多网站,但找不到简单的解决方案

下面是我的最新代码,它仍然在snackbar上重叠

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item_col_top"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".item.ItemActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <include
        android:id="@+id/item_toolbar"
        layout="@layout/toolbar" />
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/item_rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="60dp"
        android:layout_marginTop="8dp"
        tools:listitem="@layout/list_item"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/item_cl_add"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:layout_dodgeInsetEdges="bottom"
        android:layout_gravity="bottom">

        <AutoCompleteTextView
            android:id="@+id/item_ac_add"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:hint="@string/item_edit_text_hint"
            android:imeOptions="actionDone"
            android:inputType="text"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/item_b_add"
            app:layout_constraintTop_toTopOf="parent"
            tools:targetApi="o" />

        <Button
            android:id="@+id/item_b_add"
            android:layout_width="42dp"
            android:layout_height="42dp"
            android:layout_marginStart="8dp"
            android:background="@color/colorForeground"
            android:stateListAnimator="@null"
            android:text="+"
            android:textColor="@android:color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

下面是带有snackbar(不好)的屏幕截图


坐标布局类似于框架布局,因为视图可以自由重叠。因此,填充物无法解决问题


如果您不想让“回收器”视图与“底部视图”重叠,您应该将它们都包装成垂直直线布局。

您能提供屏幕截图吗?添加屏幕截图谢谢您的回答,但如果我错了,请纠正我,以避免蛇形条与“底部视图”重叠,我需要将
app:layout\u dodgeinsetteges=“bottom”
放置在LinearLayout,这将导致snackbar将整个LinearLayout推到工具栏后面,直到snackbar关闭,我才会看到第一行。有什么我可以避免的吗?如果你想避免的话,我会回到以前的设置(没有线性布局),并在底部视图中添加一个白色背景。这样,底部视图被snackbar向上推,但recyclerview保持不变(基本上,这是您在第二个屏幕截图中所做的,但现在底部视图的背景隐藏了重叠)。我也想到了这一点,但当snackbar向上时,它仍将与最后一行重叠。这很奇怪,因为似乎所有教程都建议使用协调器布局来避免snackbar重叠,但对于像recyclerView overlap这样的视图,没有一个好的解决方案。您可以尝试的另一个选项是将底部视图锚定在屏幕的底部,并使snackbar显示在其上方。要实现这一点,您需要将底部视图从CoordinatorLayout中取出,并将它们都包装在LinearLayout中。但我不知道这是否符合你的目标。我最终从
CoordinatorLayout
改回了
ConstraintLayout
。为了避免snackbar与底部视图重叠,我为
onShown
onDismissed
snackbar创建了一个回调函数。当snackbar打开时,我添加了
mSnackbar.getView().getHeight()
layout\u marginBottom
,然后将其删除。它似乎工作得很好,但我会继续测试,我最担心的是,因为我在网上没有看到任何这样的方法。