Android - Detect when the last item in a RecyclerView is visible

后端 未结 4 747
挽巷
挽巷 2020-12-03 04:46

I have a method that will check if the last element in a RecyclerView is completely visible by the user, so far I have this code The problem is how to check if the Recycler

4条回答
  •  既然无缘
    2020-12-03 05:45

    You should use your code with following change:

    boolean isLastVisible() {
        LinearLayoutManager layoutManager =((LinearLayoutManager) rv.getLayoutManager());
        int pos = layoutManager.findLastCompletelyVisibleItemPosition();
        int numItems =  disp_adapter.getItemCount();
        return (pos >= numItems - 1);
    }
    

    Be careful, findLastCompletelyVisibleItemPosition() returns the position which start at 0. So, you should minus 1 after numItems.

提交回复
热议问题