(Smooth)ScrollToPosition doesn't work properly with RecyclerView

后端 未结 16 1385
既然无缘
既然无缘 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 04:47

    I was facing a weird issue wherein smoothScrollToPosition only worked occasionally.

    After putting the smoothScrollToPosition inside Handler Post Delayed with 1 second delay, it worked fine.

    Refer to the following Kotlin example:

    Handler().postDelayed({
    
       recyclerViewObject.smoothScrollToPosition(0) // mention the position in place of 0
    
    }, 1000) // 1000 indicates the 1 second delay.
    

提交回复
热议问题