(Smooth)ScrollToPosition doesn't work properly with RecyclerView

后端 未结 16 1396
既然无缘
既然无缘 2020-12-03 04:29

I\'m using basic RecyclerView with GridLayoutManager. I observed that nor smoothScrollToPosition nor scrollToPosition works properly.

a) when using smoothScrol

16条回答
  •  忘掉有多难
    2020-12-03 05:05

    If you are trying to do a quick scroll to a position at the top of the RecyclerView, just use LinearLayoutManager.scrollToPositionWithOffset with 0 as the offset.

    Example:

    mLinearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(mLinearLayoutManager);
    
    mLinearLayoutManager.scrollToPositionWithOffset(myPosition, 0);
    

    smoothScrollToPosition is very slow. If you want something fast go with scrollToPositionWithOffset.

提交回复
热议问题