检测 RecyclerView 的顶部?

Detect the top of RecyclerView?

我有一个 RecyclerView,首先它向下滚动,现在当我们向上滚动时,它到达最高点。我想检测一下。有什么办法吗?我的 AppBar 的高度大于设备宽度。所以它会导致滚动。我想通过让最热门的听众手动展开 AppBar 来避免一闪而过。

    if (layoutManager.firstCompletelyVisibleItemPosition() == 0) {
    //this is the top of the RecyclerView 
    }

此代码我已经使用过,但我的问题是在放置此代码后我无法向上滚动 RecyclerView。因为我的 RecyclerView 使用 GridLayoutManager 3 列。

如果您在 RecyclerView 上设置了 LinearLayoutManager,您可以使用它来查找第一个可见项目:

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerview.setLayoutManager(layoutManager);

if (layoutManager.firstCompletelyVisibleItemPosition() == 0) {
    //this is the top of the RecyclerView
    //Do Something
}