回收站视图滚动但没有滚动到最后

Recycler view scrolls but does not scroll to the end

我正在通过 Kotlin 和 Firebase 设计一个购物应用程序。我在内置片段中使用回收器视图。有一个 activity 负责多个片段,例如一个片段负责显示订单,一个片段负责显示所有产品等。我从 firebase 获取所有数据并通过回收器视图将其显示在片段中.问题是回收器视图滚动但不会滚动到页面末尾。有人可以指导我。我附上了两张截图

(Recycler 视图不会滚动到最后一个子元素的末尾,即“TAP TO KNOW MORE”文本视图对于 Recycler 视图的最后一个元素不可见,它只是停止滚动)

我的 activity 就是这样设计的 ->

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/nav_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="0dp"
        android:layout_marginEnd="0dp"
        android:background="@color/purple_500"
        app:itemIconTint="@color/white"
        app:itemTextColor="@color/bgColor"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:labelVisibilityMode="unlabeled"
        app:menu="@menu/bottom_nav_menu" />

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@id/nav_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:navGraph="@navigation/mobile_navigation"/>

</androidx.constraintlayout.widget.ConstraintLayout>

我的片段是这样设计的 ->

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activities.ui.fragments.DashboardFragment">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_dashboard_items"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <TextView
        android:id="@+id/tv_no_dashboard_item_found"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:textAlignment="center"
        android:textSize="20sp"
        android:text="@string/no_dashboard_item_found"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

这就是我的回收站视图项目的设计方式 ->

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="200dp"
    android:layout_height="265dp"
    xmlns:app="http://schemas.android.com/apk/res-auto">


    <androidx.cardview.widget.CardView
        android:id="@+id/view"
        android:layout_width="180dp"
        android:layout_height="wrap_content"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

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

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/iv_item_image_dashboard"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center"
                android:layout_marginTop="15dp"
                />

            <com.example.shopperista.utils.CustomTextViewStyleBold
                android:id="@+id/tv_item_name_dashboard"
                android:layout_marginTop="10dp"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:text="@string/guitar"
                android:textSize="14sp"
                android:layout_marginStart="10dp"
                />

            <com.example.shopperista.utils.CustomTextViewStyle
                android:id="@+id/tv_item_price_dashboard"
                android:layout_marginTop="10dp"
                android:layout_width="150dp"
                android:paddingTop="2dp"
                android:layout_height="wrap_content"
                android:textSize="12sp"
                android:paddingBottom="10dp"
                android:text="@string/rs_2500"
                android:layout_marginStart="10dp"
                />

            <androidx.cardview.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:elevation="10dp"
                app:cardCornerRadius="20dp"
                android:layout_marginBottom="20dp"
                android:layout_marginTop="15dp"
                android:layout_gravity="center">

                <TextView
                    android:padding="8dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/tap_to_know_more"
                    android:textSize="10sp"
                    />
            </androidx.cardview.widget.CardView>

        </LinearLayout>
    </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

<fragment> 的 XML 更改如下:

<fragment
    android:id="@+id/nav_host_fragment"
    android:name="androidx.navigation.fragment.NavHostFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:defaultNavHost="true"
    app:layout_constraintBottom_toTopOf="@id/nav_view"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:navGraph="@navigation/mobile_navigation"/>

主要部分是将 android:layout_heightmatch_parent 更改为 0dp,因为您希望片段在排除底部导航后占用剩余的 space。如果使用match_parent,片段的底部隐藏在底部导航栏后面

在你的片段中制作android:layout_height="0dp",你的底部导航重叠在你的片段之上