android-discuss icon indicating copy to clipboard operation
android-discuss copied to clipboard

nestedscrollview 嵌套 recyclerview 加载更多bug

Open peter100u opened this issue 8 years ago • 3 comments

当使用NestedScrollView嵌套RecyclerView加载更多数据的时候,会有bug NestedScrollView 嵌套RecyclerView 会导致 RecyclerView的item全部绘制出来。超出屏幕的 item会在 NestedScrollView屏幕外面。在这种嵌套情况下RecyvlerView的高度是无限的,recyclerview 刷新机制是 最下面可见的item+pageSize>totalItem,这样就会一直触发刷新机制, 就会无限触发加载更多的逻辑,目前没有解决,有好的方案吗?

peter100u avatar Jun 08 '17 02:06 peter100u

@RelocationTime 我也遇到过这个问题,暂时的办法是,比如你分页加载,每一页最下面那个item就是"加载更多",我做成了点击加载更多,也就是说,不点的话,是不会请求接口拉取下一页数据的。 还有个另类的方法,就是通过Rect去获取View的可见性(大致是根据矩形显示部分来计算的,可以搜索如何获取View可见区域),当“加载更多”那个item里的控件可见区域大于0时,就触发加载,类似上面的点击事件。不过这个办法我没试过,我目前暂时用的点击加载。

ysy950803 avatar Aug 09 '17 14:08 ysy950803

现在这个问题解决了没

18740461298 avatar Aug 07 '18 03:08 18740461298

我是这么做的 重新 NestedScrollView setOnScrollChangeListener 方法 ,监听滑动mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { @Override public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) { LogUtils.e("BOTTOM SCROLL"); if (loadMoreEnd) { //加载数据 } } } });

xmlxin avatar Sep 13 '18 03:09 xmlxin