本文介绍了在 NestedScrollView 中找不到 RecyclerView 可见项位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果 RecyclerView 中的第一个/最后一个完全可见的项目位于 NestedScrollView 内,并且回收器具有 nestedScrollingEnabled="false" 以便与 RecyclerView 上方的其他视图平滑滚动,我该如何获取它.

How do I get the first/ last completely visible item in a recyclerview if it is inside a NestedScrollView and the recycler has nestedScrollingEnabled="false" for smooth scrolling with other views above the RecyclerView.

所有这些功能

int findFirstVisibleItemPosition();int findFirstCompletelyVisibleItemPosition();int findLastVisibleItemPosition();int findLastCompletelyVisibleItemPosition();

要么返回在 recyclerView 中创建的第一个/最后一个项目.

either return the first/last item created in the recyclerView.

我想找到当前可见的项目,因为我想让 RecyclerView 无限滚动,如果只剩下几个项目要滚动,我应该获取数据.

I want to find the current visible item because I want to make the RecyclerView scroll infinitely and I should fetch data if only a few items are left to scroll.

谢谢

推荐答案

好吧,我找不到任何方法可以使两个 RecyclerView 可以在 NestedScrollView 中并且仍然说哪个项目在屏幕上可见.

Well I couldn't find any way in which two RecyclerView could be inside a NestedScrollView and still say which item is visible on the screen.

所以我的解决方案是删除 NestedScrollView 并使 Vertical RecyclerView 成为页面中的主视图,并添加 Horizo​​ntal RecyclerView 作为 Vertical Recycler 的第一项.因为我只想知道Vertical Recycler的位置,我现在可以通过使用问题中提到的任何方法来获得.

So my solution was to remove the NestedScrollView and make the Vertical RecycelerView the main view in the page and add the Horizontal RecyclerView as the first item of on Vertical Recycler. As I only wanted to know the position for the Vertical Recycler, I can get that now by using any of the methods mentioned in the question.

这篇关于在 NestedScrollView 中找不到 RecyclerView 可见项位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:02