0
  • 最佳答案
    public class MyLinearSmoothScroller extends LinearSmoothScroller {
        public MyLinearSmoothScroller(Context context) {
            super(context);
        }
    
        @Override
        protected int getHorizontalSnapPreference() {
            return SNAP_TO_START;
        }
        @Override
        protected int getVerticalSnapPreference() {
            return SNAP_TO_START;  // 将子view与父view顶部对齐
        }
    }
    


    public class MyLinearLayoutManager extends LinearLayoutManager {
        public MyLinearLayoutManager(Context context) {
            super(context);
        }
    
        public MyLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
            super(context, orientation, reverseLayout);
        }
    
        public MyLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }
    
        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
            MyLinearSmoothScroller linearSmoothScroller = new MyLinearSmoothScroller(recyclerView.getContext());
            linearSmoothScroller.setTargetPosition(position);
            startSmoothScroll(linearSmoothScroller);
        }
    }
    

    自定义一下MyLinearLayoutManager 即可,主要是要修改SNAP_TO_START

    1182186833577086976  评论     打赏       痞子小小崔
    相关问题
    彭于晏盐城分晏 · recyclerview
    2019-10-30 00:34 689 2
    哦豁! · RecyclerView
    2019-12-20 04:20 1081 4
    葬礼上的假发 · Recyclerview
    2020-12-10 06:54 728 2
    Nuttertools · recyclerview联调
    2020-12-26 18:16 451 5