mcxtzhang/ZLayoutManager

将你的FlowLayoutManager用到我的布局中会出现onLayoutChildren被调用了多次的情况

Closed this issue · 2 comments

代码一行未改,ImageView的图片是从网络上加载的,在上下滑动的时候,当出现之前未出现过的ImageView就会触发onLayoutChildren,触发后整个布局就会重新回到position(0)的位置,下次滑动到该位置就正常了,但是滑动到下一行新出现的ImageView还是会重新触发onLayoutChildren,又回到顶端了,这可能是什么原因呢?

简单的总结下自己的发现吧,在LayoutManager的布局中新生成的View存在图片加载的情况下,会不断的触发RecyclerView重新Layout,解决方法是注释掉了onLayoutChildren中第二处detachAndScrapAttachedViews(recycler),然后把偏移量保存成全局的不在每次onLayoutChildren回调过程中都重新初始化为0。如果Layoutmanager的布局中不存在图片加载的话,onLayoutChildren就不会引起RecyclerView反复回调onLayoutChildren。

想问一下你是怎么解决的,方便贴下代码吗