Android Firebase chat RecyclerView auto scroll to bottom when new item is added

前端 未结 4 401
暗喜
暗喜 2020-12-18 01:35

im developing an android chat using firebase.

i tried to research about this problem but i cant find a good solutions.

hope someone can help me.

my p

4条回答
  •  时光说笑
    2020-12-18 01:53

    I know it is an old thread, but maybe this will be helpful.

    In place where you add new message:

    yourRVAdapter.addMessage("New message")
    val position = yourRVAdapter.itemCount.minus(1) // itemCount will return the size of RV items 
    //Now just call your recyclerView.scrollToPosition(int)
    chatRV.scrollToPosition(position)
    

提交回复
热议问题