private LinearLayoutManager mManager;
mManager=new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(mManager);
//重点
LinearSmoothScroller lss=new TopSmoothScroller(getActivity());
lss.setTargetPosition(position_3);
mManager.startSmoothScroll(lss);
2021.7.7
今天再次使用这个方法的时候,发现高版本的sdk中已经没有TopSmoothScroller类了,现在直接new LinearSmoothScroller就可以了。
以上主要实现代码
平时我们在平滑到指定item的时候经常用到
recyclerView.scrollToPosition();
recyclerView.smoothScrollToPosition();
这两个,在查看这两个方法的源码时,会发现我们其实通过LinearLayoutManager 中的
public void startSmoothScroll(RecyclerView.SmoothScroller smoothScroller) {
if (this.mSmoothScroller != null && smoothScroller != this.mSmoothScrolle