问题
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