美文网首页
RecyclerView Bug:IndexOutOfBound

RecyclerView Bug:IndexOutOfBound

作者: Nj_第一批老去的90后 | 来源:发表于2017-04-24 17:03 被阅读26次

    解决方案来源

    1.创建一个类LinearLayoutManagerWrapper继承LinearLayoutManager,重写onLayoutChildren方法

    
    public class WrapContentLinearLayoutManager extends LinearLayoutManager {  
        public WrapContentLinearLayoutManager(Context context) {  
            super(context);  
        }  
      
        public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {  
            super(context, orientation, reverseLayout);  
        }  
      
        public WrapContentLinearLayoutManager(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();  
            }  
        }  
    }
    

    2.设置RecyclerView的布局管理为WrapContentLinearLayoutManager对象

    设置RecyclerView的布局管理为WrapContentLinearLayoutManager对象
    
    

    相关文章

      网友评论

          本文标题:RecyclerView Bug:IndexOutOfBound

          本文链接:https://www.haomeiwen.com/subject/ancczttx.html