1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package safeluck.drive.evaluation.adapter;
 
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
 
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
 
import com.anyun.exam.lib.MyLog;
 
import safeluck.drive.evaluation.fragment.BaseDatasFragment;
 
public class WrapContentLinearLayoutManager extends LinearLayoutManager {
    private static final String TAG = "WrapContentLinearLayoutManager";
    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来捕获这个异常即可
        try {
            super.onLayoutChildren(recycler, state);
        } catch (IndexOutOfBoundsException e) {
            MyLog.i(TAG, "onLayoutChildren: "+e.getLocalizedMessage()+" : "+e.getMessage());
            e.printStackTrace();
        }
    }
}