How to use RecyclerView.scrollToPosition() to move the position to the top of current view?

前端 未结 5 707
长情又很酷
长情又很酷 2020-12-01 03:03

The RecyclerView.scrollToPosition() is extremely strange. for example, supposed a RecyclerView named \"rv\".

  1. if now i

5条回答
  •  [愿得一人]
    2020-12-01 03:22

    If you want to scroll to a specific position and that position is the adapter's position, then you can use StaggeredGridLayoutManager scrollToPosition

       StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
       staggeredGridLayoutManager.scrollToPosition(10);
       recyclerView.setLayoutManager(staggeredGridLayoutManager);
    

提交回复
热议问题