版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010095372/article/details/80744713
在Android 上喜欢用RecyclerView,也挺好用的,但是发现重载数据的时候,就是说在一个RecyclerView里面变换它item的长度,我就会发生这个错误。上网找了一圈是它原生的bug,解决办法也有好多
这个对我有用重新弄一个LayoutManager,重写onLayoutChildren方法,在遇到这个异常时,直接抛出异
也有人说清理列表里的view,但我试了还是不行
public class MyContentLinearLayoutManager extends LinearLayoutManager {
public MyContentLinearLayoutManager(Context context){
super(context);
}
public MyContentLinearLayoutManager(Context context,int orientation,boolean reverseLayout){
super(context,orientation,reverseLayout);
}
public MyContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
}catch (IndexOutOfBoundsException e){
e.printStackTrace();
}
}
}
就酱