android Recyclerview Layoutmanager's onLayoutChildren called when item content is changed

别来无恙 提交于 2020-03-01 04:33:10

问题


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.

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.

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 ?

Thanks,


回答1:


Yes, this is how layout system works. If a child requests a layout, all of its parents' onLayout will be called.

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.



来源:https://stackoverflow.com/questions/29721607/android-recyclerview-layoutmanagers-onlayoutchildren-called-when-item-content-i

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