我怎么能检查回收视图被滚动到其顶部(列表的开头),而无需使用findFirstCompletelyVisibleItemPosition
?检查RecyclerView是在上面滚动(findFirstCompletelyVisibleItemPosition将无法正常工作)
说明:我不能使用这种方法,因为RecyclerView
的项目是大,有时永远不会“完全可见”,所以该方法将返回-1(RecyclerView.NO_POSITION
)
我需要知道这火只有当回收商视图达到最高点时才采取行动。
val manager = timelineRecyclerView?.layoutManager as StaggeredGridLayoutManager
val visibles = manager.findFirstCompletelyVisibleItemPositions(null)
解决:其中包括一些代码,以帮助
timelineRecyclerView.addOnScrollListener(object:RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView:RecyclerView,
newState:Int) {
super.onScrollStateChanged(recyclerView, newState)
}
override fun onScrolled(recyclerView:RecyclerView, dx:Int, dy:Int) {
super.onScrolled(recyclerView, dx, dy)
currentTimelinePosition += dy
Log.wtf("position", currentTimelinePosition.toString())
//if the timeline position is on its start, allow swipe and refresh
swipeLayout.isEnabled = currentTimelinePosition == 0
}
})
我注意到你用'pull-to-refresh'标记了,究竟是什么与此有关?如果我们知道更多细节,可能会有更好的解决方案。 –
后面的问题是RecyclerView在SwipeRefreshLayout中。刷卡有时会刷新错误的位置。 I.E.当列表不在顶部时。所以我只允许在RecyclerView在顶部时刷新 – cesarsicas
啊,我明白了。这很奇怪,在'RecyclerView'中我没有这个问题,但也许是那些较大的项目。 –