RecylerView滚动到指定位置的方法

2020-07-07  本文已影响0人  Charein

public class TopSmoothScroller extends LinearSmoothScroller {
    TopSmoothScroller(Context context) {
        super(context);
    }
    @Override
    protected int getHorizontalSnapPreference() {
        return SNAP_TO_START;//具体见源码注释
    }
    @Override
    protected int getVerticalSnapPreference() {
        return SNAP_TO_START;//具体见源码注释
    }
}

然后调用LinearLayoutManager的startSmoothScroll即可

final TopSmoothScroller mScroller = new TopSmoothScroller(getActivity());
mScroller.setTargetPosition(integer);
mManager.startSmoothScroll(mScroller);
上一篇下一篇

猜你喜欢

热点阅读