android - getLayoutPosition与getAdapterPosition
高洛峰
高洛峰 2017-04-17 17:45:11
0
1
710

看了stackoverflow RecyclerView.ViewHolder - getLayoutPosition vs getAdapterPosition上的解释

然后又看了 它俩的源码的注释

还是没有分清它俩的具体区别

有没有人具体的说明一下??!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
小葫芦

When adapter contents change (and you call notify*) RecyclerView requests a new layout. From that moment, until layout system decides to calculate a new layout (<16 ms), the layout position and adapter position may not match because layout has not reflected adapter changes yet.

The answer is very clear. The specific difference is that there will be a time difference between the positions of the adapter and layout (<16ms). If you change the data of the Adapter and then refresh the view, it will take a while for the layout to update the view. In this paragraph In time, the positions returned by these two methods will be different.

In addition, the answer also mentioned that the position in the Adapter cannot be obtained immediately after notifyDataSetChanged, and can only be obtained after the layout is completed. notifyDataSetChanged之后并不能马上获取Adapter中的position, 要等布局结束之后才能获取到.

而对于Layout的position, 在notifyItemInserted

As for Layout's position, after notifyItemInserted, Layout cannot get the new position immediately because the layout has not been updated yet (it takes About this🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template