查找回收者视图中的第一个可见项目是否为列表中的第一项 [英] Find if the first visible item in the recycler view is the first item of the list or not

查看:50
本文介绍了查找回收者视图中的第一个可见项目是否为列表中的第一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含13个数据项的回收站视图.我想找出列表中的第一项是否可见?

I have a recycler view with 13 data items. I want to find out whether the first item of my list is visible or not?

我知道诸如 findFirstVisibleItemPosition findLastVisibleItemPosition 之类的方法,但是它们没有告诉第一个可见项是否实际上是列表中的第一项.

I am aware about the methods like findFirstVisibleItemPosition and findLastVisibleItemPosition but they did not tell whether the first visible item is actually the first item of the list or not.

我要解决的问题是,我有一个视图寻呼机作为回收器视图的第一项,当用户向下滚动并变得完全不可见时,我想停止自动滚动.

The problem that I am trying to solve is this, I have a view pager as the first item of my recycler view and I want to stop auto scroll when user scrolls down and it becomes completely invisible.

如果有人对如何执行此操作有任何想法,请提供帮助.

Please help if anyone has any idea about how to do this.

推荐答案

您可以通过检查

You can do it by checking if findFirstVisibleItemPosition is 0 or not, like this :

// layoutManager is your recycler view's layout manager
int position = layoutManager.findFirstVisibleItemPosition();
if(position != 0){
    stopAutoScroll();
}else{
    startAutoScroll();
}

即,如果 findFirstVisibleItemPosition 返回 0 ,我们应该开始自动滚动;如果不是 0 ,则停止滑动.

i.e, if findFirstVisibleItemPosition returns 0 we should start auto scroll and if it is not 0, stop swiping.

这篇关于查找回收者视图中的第一个可见项目是否为列表中的第一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆