How to tell RecyclerView to start at specific item position

前端 未结 6 2144
难免孤独
难免孤独 2021-02-20 10:43

I want my RecyclerView with LinearLayoutManager to show up with scroll position at specific item after adapter got updated. (not first/last position) Means the at first (re-)lay

6条回答
  •  灰色年华
    2021-02-20 11:21

    If your only motive is to start the recyclerView from a specific position without any scroll-like animation I'll suggest using StaggeredGridLayoutManager

    val staggeredGridLayoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL)//or VERTICAL
                staggeredGridLayoutManager.scrollToPosition(specificPosition)
    
    recyclerView.apply{
        layoutManager = staggeredGridLayoutManager
    }
    

提交回复
热议问题