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

后端 未结 4 743
挽巷
挽巷 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:42

    Assuming you're using LinearLayoutManager, this method should do the trick:

    boolean isLastVisible() {
      LinearLayoutManager layoutManager = ((LinearLayoutManager)mRecyclerView.getLayoutManager());
      int pos = layoutManager.findLastCompletelyVisibleItemPosition();
      int numItems = mRecyclerView.getAdapter().getItemCount();
      return (pos >= numItems);
    }
    

提交回复
热议问题