更改项目内容时调用android Recyclerview Layoutmanager的onLayoutChildren [英] android Recyclerview Layoutmanager's onLayoutChildren called when item content is changed
问题描述
我有一个带有自定义布局管理器的回收器视图(其twowayview staggeredgridview布局管理器
i have a recycler view with custom layout manager ( its a twowayview staggeredgridview layout manager https://github.com/lucasr/twoway-view/blob/master/layouts/src/main/java/org/lucasr/twowayview/widget/StaggeredGridLayoutManager.java )
我正在使用它来显示图像列表. 这些图像是异步加载的,也就是说,当这些项变为活动状态时,我会解码图像数据,然后将该位图加载到这些列表项视图中.
i am using this to display list of Images. These images are loaded asynchronously, meaning ,when the items becomes active, i decode image data and then load that bitmap onto these list item views.
现在,问题在于,每当我将图像位图设置到项目的图像视图上时,就会导致在布局管理器上调用onLayoutChildren,该布局管理器随后会重新布局所有子项.
now, problem is whenever i set image bitmap onto an item's imageview, it causes onLayoutChildren to be called on the layout manager, which then lays out all the children again.
这是预期的行为吗?含义是,更改子元素(这里为imageview)的内容会导致父recyclerview在其layoutmanager上发出onLayoutChildren吗?
Is this an expected behavior ? meaning, changing the content of child element ( here, imageview ) causes the parent recyclerview to issues a onLayoutChildren on its layoutmanager ?
如果没有,那我该如何预防呢?
if not, then how do i prevent this ?
谢谢
推荐答案
是的,这是布局系统的工作方式.如果孩子要求布局,则将调用其父母的所有onLayout.
Yes, this is how layout system works. If a child requests a layout, all of its parents' onLayout will be called.
如果新位图到来时视图未更改大小,则可以通过编写自定义视图来扩展视图并阻止requestLayout
调用,以处理该视图.
在RecyclerView的源代码中搜索eatRequestLayout
,以获取有关如何执行此操作的想法.
If your view does not change size when new bitmap arrives, you can handle it by writing a custom view that extends your view and prevents requestLayout
calls.
Search for eatRequestLayout
in RecyclerView's source code to get an idea about how to do it.
这篇关于更改项目内容时调用android Recyclerview Layoutmanager的onLayoutChildren的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!