Check if RecyclerView is scrollable

后端 未结 9 1742
走了就别回头了
走了就别回头了 2021-02-02 10:21

How to check if a RecyclerView is scrollable, ie, there are items below/above the visible area

I have a dropdown in my recycler view which works by using

9条回答
  •  借酒劲吻你
    2021-02-02 10:45

    There you go:

    public boolean isRecyclerScrollable() {
      LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
      RecyclerView.Adapter adapter = recyclerView.getAdapter();
      if (layoutManager == null || adapter == null) return false;
    
      return layoutManager.findLastCompletelyVisibleItemPosition() < adapter.getItemCount() - 1;
    }
    

提交回复
热议问题