NestedScrollView + RecyclerView加载缓慢

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

我必须说的第一件事是,有太多与此问题类似的问题。因此,请先将其标记为重复分析一次。

我在这两个“回收者视图”的内部有一个嵌套滚动视图。第一个是水平滚动。第二个是垂直滚动。

这些功能运行正常。现在的问题是第一次加载需要20秒。因此调用了ANR服务。加载后,滚动效果也很完美。

RestarantListAdapter restarantListAdapter = new RestarantListAdapter(activity, restaurants_1);
                    LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(activity, RecyclerView.VERTICAL, false);
                    binding.rvRestaurants.setLayoutManager(linearLayoutManager1);
                    binding.rvRestaurants.setAdapter(restarantListAdapter);

binding.rvRestaurants.setNestedScrollingEnabled(false);

ViewCompat.setNestedScrollingEnabled(binding.rvRestaurants, false);

我尝试了上面的代码。还有其他可能解决第一次加载的问题。

android android-recyclerview android-nestedscrollview
1个回答
0
投票

当您在NestedScrollView中使用RecyclerView时,将立即绘制所有项目(您可以检查onBindViewHolder的调用次数)。因此,您基本上失去了RecyclerView所提供的所有性能改进,并且得到了类似ListView的东西。因此,如果您不必真正在NestedScrollView中使用RecyclerView,请不要这样做。

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