Android上CoordinatorLayout中RecyclerView下方的底视图 [英] bottom view below RecyclerView in CoordinatorLayout on android

查看:132
本文介绍了Android上CoordinatorLayout中RecyclerView下方的底视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从ConstraintLayout切换为CoordinatorLayout以避免Snackbar与底部视图重叠.虽然它在只有工具栏,RecyclerView和Floating按钮的屏幕中运行良好,但在第二个屏幕中,我很难在RecyclerView下方添加视图,同时又避免与RecyclerView重叠

I switched from ConstraintLayout to CoordinatorLayout to avoid snackbar overlapping with my bottom view. While it worked very well in a screen with only a toolbar, RecyclerView and Floating button, in the second screen i am having a really hard time to add a view below the RecyclerView while avoiding it being overlapped with the RecyclerView

到目前为止,我最好的解决方案(如下)是在recyclerView中添加大约 80dp paddingBottom 属性.这看起来像解决了问题,但是当快餐栏打开时,底部视图 android:id ="@ + id/item_cl_add" 再次与recyclerView重叠.当然,我可以添加更多的 paddingBottom 来补偿快餐栏的大小,但这意味着我将损失大约20dp的房地产(不是一个好主意).

My best solution yet (below) was to add paddingBottomattribute of about 80dpto the recyclerView. This looks like it solves the problem but when the snackbar is UP, the bottom view android:id="@+id/item_cl_add" again will overlap with the recyclerView. Of course, i can add more paddingBottom to compensate the size of the snackbar, but that means i will be losing about 20dp of real estate (not a good idea).

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

I checked many websites but could not find an simple solution

bellow是我的最新代码,仍然在快餐栏上重叠

bellow is my latest code which still overlaps on 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>

以下是屏幕截图没有,没有小吃店()

Below is a screenshot without a snackbar (Good)

下面是带有快餐栏的屏幕截图(不好)

Below is a screenshot with the snackbar (not good)

推荐答案

CoordinatorLayout与FrameLayout相似.因此,填充无法解决问题.

CoordinatorLayout is similar to FrameLayout, in the sense that views can overlap freely. So paddings cannot solve the problem.

如果您不希望回收器视图与底视图重叠,则应将它们都包装在垂直的LinearLayout中.

If you don't want the recycler view to overlap with the bottom view, you should wrap them both in a vertical LinearLayout.

这篇关于Android上CoordinatorLayout中RecyclerView下方的底视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆