两个recyclerview放在同一个布局中的坑

问题描述:比如把两个recyclerview放到一个linearlayout中,两个recyclerview分别用weight来控制大小,将layout_width(或layout_height)设为0dp。如果这样设置,会发现,在刷新recyclerview时(notifyDataSetChanged),adapter会bind所有views,而不是可见区域内的views,并且scrollToPosition方法也会有异常表现。

解决方法:将recyclerview的layout_width(或layout_height)设为match_parent或wrap_content即可。

参考stackoverflow上的问答:

https://stackoverflow.com/questions/36065736/recyclerview-23-2-x-height-0dp-causes-onbind-called-for-all-items-and-scrolltopo

https://stackoverflow.com/questions/35747268/recycleview-set-wrong-height-for-items

你可能感兴趣的:(两个recyclerview放在同一个布局中的坑)