嵌套滚动视图内的RecyclerView最初加载速度很慢

问题描述 投票:0回答:2

我有一个如下的

recyclerView
。这是在
fragment
内,这是应用程序启动时显示的第一个屏幕。在我添加
NestedScrollView
之前,
recyclerView
用于快速加载数据(或者立即显示recyclerView)。现在,添加
NestedScrollView
后,
recyclerView
需要一些时间来加载数据(或显示 recyclerView)。

不知道是recyclerView显示晚了还是数据加载慢了

注意:一旦显示,滚动时就没有问题,项目在滚动时以正常速度加载。该问题仅在初始加载时出现。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:background="@color/colorOffWhite"
    android:orientation="vertical"
    tools:context=".ui.fragments.HomeFragment">

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

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

                <androidx.viewpager2.widget.ViewPager2
                    android:id="@+id/vp_deals"
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:orientation="horizontal"
                    android:visibility="gone"
                    tools:visibility="visible"/>

                <TextView
                    android:id="@+id/tv_all_deals"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/colorWhite"
                    android:text="All Deals"
                    android:layout_gravity="bottom|right"
                    android:layout_marginEnd="5dp"
                    android:layout_marginBottom="3dp"
                    android:background="@drawable/app_gradient_color_background"
                    android:padding="3dp"
                    android:clickable="true"
                    android:focusable="true"
                    android:foreground="?android:attr/selectableItemBackgroundBorderless"/>

            </FrameLayout>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_home_items"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:nestedScrollingEnabled="false"
                android:focusableInTouchMode="true"/>

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</RelativeLayout>
android android-recyclerview android-nestedscrollview
2个回答
0
投票

android:nestedScrollingEnabled =“假”


-2
投票

当您尝试在 NestedScrollView 中创建 recyclerview 时,这是一个常见问题,导致回收器视图高度未定义

尝试设置

recyclerview.setNestedScrollingEnabled(false);

我想这会解决这个问题

另外,当回收器视图放置在nestedScrollView中时,最好为它定义一定的高度

© www.soinside.com 2019 - 2024. All rights reserved.