Use PagedListAdapter inside NestedScrollView

你说的曾经没有我的故事 提交于 2021-01-27 04:07:08

问题


I have a RecyclerView that has a PagedListAdapter.

When I put the RecyclerView inside NestedScrollView the PagedList cannot compute the end of the list so start requests continuous burst for new data.

The main question is How should I use PagedListAdapter inside NestedScrollView?


回答1:


I had a similar problem, and it seems to be caused by the fact that NestedScrollView provides infinite dimensions and so RecyclerView will layout all its children. so I looked on github and found an implementation of NestedScrollView that solved the problem by passing View.MeasureSpec.AT_MOST down to the RecyclerView:

https://gist.github.com/danaimset/abacaa50d746a4537686a08ecc33c1a9




回答2:


Based on Android documentation:

Never add a RecyclerView or ListView to a scroll view. Doing so results in poor user interface performance and a poor user experience.

The best new way is to use MergeAdapter. It added to Recyclerview v1.2.0alpha. So add this dependency:

implementation "androidx.recyclerview:recyclerview:1.2.0-alpha03"

If you want to put two Adapters in one recyclerView, follow this Guide:

then make an instance of MakeAdapter and pass your adapters on it then set it as RecyclerViewAdapter:

MergeAdapter ma = new (firstAdapter, secondAdapter);
myRecyclerView.setAdapter(ma);

If you have a layout and Pagedlist, follow this Guide:

Then Make and Simple ViewHolder and put the first layout on it. Then make MergeAdapter then add your layout's adapter and then PagedList's adapter, then add adapter of PagedList:

MergeAdapter ma = new MergeAdapter();
ma.addAdaper(simpleAdapter);
ma.addAdapter(pagedListAdapter);

then set this mergeAdapter to recyclerView's adapter;

myRecyclerView.setAdapter(ma);


来源:https://stackoverflow.com/questions/50563825/use-pagedlistadapter-inside-nestedscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!