Detect when RecyclerView reaches the bottom most position while scrolling

后端 未结 11 1881
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 19:56

I have this code for a RecyclerView.

    recyclerView = (RecyclerView)rootview.findViewById(R.id.fabric_recyclerView);
    recyclerView.setLayoutManager(layo         


        
11条回答
  •  旧时难觅i
    2020-11-29 20:50

    After not being satisfied with most the other answers in this thread, I found something I think is better and is not anywhere on here.

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (!recyclerView.canScrollVertically(1) && dy > 0)
            {
                 //scrolled to bottom
            }else if (!recyclerView.canScrollVertically(-1) && dy < 0)
            {
                //scrolled to bottom
            }
        }
    });
    

    This is simple and will hit exactly one time under all conditions when you have scrolled to the top or bottom.

提交回复
热议问题