How to get all Recycler View item view position ( x,y ) in nested scrollview

大城市里の小女人 提交于 2021-01-27 21:10:50

问题


I have to draw a curved line on the left side of recycler view ( which connect all the item in the recyclerview).But i cant get all of the position of recyclerview item to start draw my custom view.I tryed to get the x,y position inside onBindViewHolder but it not work ( i though when inside nestedscrollview it just like a tableview).So how can i get all the position of recyclerview's items after set it adapter

Here is the screen shot of what i have to do: https://imgur.com/a/C1jTNKr


回答1:


If your RecyclerView has hundreds of items, you shouldn't put it inside NestedScrollView or try to get any measure of all items at once.

The reason is: RecyclerView will have to measure layout for all items at once, which is totally opposite with the purpose of RecyclerView (calculate layout for item when needed) and lead to a very bad performance, very laggy or even freeze your app (if there are about 1000 items)

In your case, I think you should try to draw each path of the line inside each onBindViewHolder() as part of each item. If the logic to calculate how each draw is drawn is not too complex, I think this is an doable solution to consider



来源:https://stackoverflow.com/questions/57917074/how-to-get-all-recycler-view-item-view-position-x-y-in-nested-scrollview

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