OnScrollListener接口

OnScrollListener接口官方定义是:Interface definition for a callback to be invoked when the list or grid has been scrolled.翻译过来大意是指:当列表或者网格(AbsListView抽象类的实现子类,一般应该是指ListView类和GridView类及其子类)产生了滚动行为时,将会回调该接口。该接口是AbsListView类内部的一个静态类。所以,一般的控件比如button,textView等并不能添加该接口监听。

滚动行为有三种状态:

1.  SCROLL_STATE_FLING : The user had previously been scrolling using touch and had performed a fling.可理解为手指触摸屏幕滑动了一下,松开手后由于惯性view仍会滑动一段距离,这一过程即位Fling(猛冲)。对应的整形常量值为2。

2. SCROLL_STATE_IDLE :  The view is not scrolling.指view不再滚动。对应的整形常量值为0。

3. SCROLL_STATE_TOUCH_SCROLL :The user is scrolling using touch, and their finger is still on the screen.指按着屏幕滑动时的状态。对应的整形常量值为1。

该接口有两个抽象方法分别为:onScrollStateChanged(),和onScroll()

其中:void onScrollStateChanged(AbsListView view,   int scrollState)会在滚动状态发生改变时回调,比如从滑动状态到停止下来时就会回调该方法。它的两个参数:view表示添加了该接口监听的组件,scrollState表示当前的滚动状态。

void onScroll(AbsListView view,
              int firstVisibleItem,
              int visibleItemCount,
              int totalItemCount)
Callback method to be invoked when the list or grid has been scrolled. This will be called after the scroll has completed

参数:
view - The view whose scroll state is being reported
firstVisibleItem - the index of the first visible cell (ignore if visibleItemCount == 0)指view中可看到的第一项所对应的索引值。
visibleItemCount - the number of visible cells指整个view中可看到的条目的数量。
totalItemCount - the number of items in the list adaptor。指整个view中所包含的总的条目的数量。
onScroll每次产生滚动行为时都会调用。经测试,当触摸一下屏幕时它会执行一次,按着屏幕滑动时,它会不断执行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值