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

前端 未结 5 716
长情又很酷
长情又很酷 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:17

    If I understand the question, you want to scroll to a specific position but that position is the adapter's position and not the RecyclerView's item position.

    You can only achieve this through the LayoutManager.

    Do something like:

    rv.getLayoutManager().scrollToPosition(youPositionInTheAdapter).
    

提交回复
热议问题