findLastVisibleItemPosition

findLastVisibleItemPosition

findLastCompletelyVisibleItemPosition:返回最后一个完全可见的视图的适配器位置。该位置不包括在最后一次布局传递之后分派的适配器更改。

findLastVisibleItemPosition:返回上一个可见视图的适配器位置。该位置不包括在最后一次布局传递之后分派的适配器更改。

我有16件物品。因此,当滚动到末尾(当最后一项完全可见时),这两种方法的结果均为16。但是当我滚动到末尾但最后一项是一半可见时,findLastCompletelyVisibleItemPosition显示14,而findLastVisibleItemPosition显示15。

有人可以解释一下为什么它显示14吗?这两个功能的确切区别是什么?

@Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

        RecyclerView.LayoutManager linearLayoutManager = recyclerView.getLayoutManager();

        if(linearLayoutManager != null && linearLayoutManager instanceof LinearLayoutManager) {
            int position = ((LinearLayoutManager) linearLayoutManager).findLastCompletelyVisibleItemPosition();
            int position1 = ((LinearLayoutManager) linearLayoutManager).findLastVisibleItemPosition();


            Log.d(TAG, "position: " + position);
            Log.d(TAG, "position1: " + position1);
        }
    }

最佳答案

如果您有16个项目,则由于您的最后一个位置是第15位,因此不可能返回16作为可见位置。

其次,很容易理解每​​种方法的命名。如果最后一个位置是第15位,并且可以看到一半,则findLastCompletelyVisibleItemPosition将返回14,而findLastVisibleItemPosition将返回15。

关于android - RecyclerView LinearLayoutManager的findLastCompletelyVisibleItemPosition()与findLastVisibleItemPosition()方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52252665/

10-09 04:06