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中所包含的总的条目的数量。
-