WrapContentLinearLayoutManager.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.cooleshow.base.widgets;
  2. import android.content.Context;
  3. import android.util.AttributeSet;
  4. import androidx.recyclerview.widget.LinearLayoutManager;
  5. import androidx.recyclerview.widget.RecyclerView;
  6. /**
  7. * Author by pq, Date on 2022/11/11.
  8. */
  9. public class WrapContentLinearLayoutManager extends LinearLayoutManager {
  10. public WrapContentLinearLayoutManager(Context context) {
  11. super(context);
  12. }
  13. public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
  14. super(context, orientation, reverseLayout);
  15. }
  16. public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
  17. super(context, attrs, defStyleAttr, defStyleRes);
  18. }
  19. @Override
  20. public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
  21. try {
  22. //解决类似java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 157(offset:157).state:588
  23. super.onLayoutChildren(recycler, state);
  24. } catch (IndexOutOfBoundsException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28. }