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
The idea is to check if the last completely visible element is the last element in the list.
private boolean isScrollable()
{
return mLinearLayoutManager.findLastCompletelyVisibleItemPosition() + 1 ==
mRecyclerViewAdapter.getItemCount();
}
boolean isScrollable() {
LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
int itemCount = mRecyclerView.getAdapter().getItemCount();
return !(itemCount == 0 ||
(layoutManager.findFirstCompletelyVisibleItemPosition() == 0 &&
layoutManager.findLastCompletelyVisibleItemPosition() == itemCount - 1));
}
What about
// 1 = down; -1 = up
recyclerView.canScrollVertically(-1)
If you want to check if there is any scrollable space, no matter which direction
cardList.canScrollVertically(1) || cardList.canScrollVertically(-1)