检查RecyclerView是否可滚动 [英] Check if RecyclerView is scrollable
本文介绍了检查RecyclerView是否可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查RecyclerView
是否可滚动,即可见区域下方/上方有项目
How to check if a RecyclerView
is scrollable, ie, there are items below/above the visible area
我的回收站视图中有一个下拉列表,可通过使用notifyItemRangeInserted()
和notifyItemRangeRemoved()
进行操作.每当发生这种情况时,我都想检查RecyclerView
是否可滚动,因为我必须相应地调整另一个视图,例如报亭中的横幅广告
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
推荐答案
去那里:
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;
}
这篇关于检查RecyclerView是否可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文