问题描述:比如把两个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置于LinearLayout中并使用权重分配高度时遇到的问题。当RecyclerView的高度设置为0dp时,会在刷新数据和滚动时出现异常行为。文章提供了正确的解决方案,并引用了StackOverflow的相关讨论。
6322

被折叠的 条评论
为什么被折叠?



