Sourabh Sourabh - 2 months ago 24
Android Question

Check if RecyclerView is scrollable

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
notifyItemRangeInserted()
and
notifyItemRangeRemoved()
. Whenever any of this happens, I want to check if the
RecyclerView
is scrollable or not, as I have to adjust another view, a banner like in newsstand, accordingly

Answer

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;
}
Comments