RecyclerView scrollToPosition not trigger scrollListener

前端 未结 8 2151
予麋鹿
予麋鹿 2021-02-01 03:35

I\'m using RecyclerView, with ScrollListener:

mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener()
{
        @Override
        public void onScr         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 04:07

    I've faced the same issue and found a workaround, which is to use the smoothScrollToPosition in layout manager. This method triggers the scroll listener. So basically this is what I use to have:

    recyclerView.scrollToPosition(recyclerAdapter.getItemCount() - 1);
    

    and now I've changed to this:

    recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, null, recyclerAdapter.getItemCount() - 1);
    

    and it's working fine for me.

提交回复
热议问题