对于ListView类的滚动监听可以通过setOnScrollListener 方法实现。
ListView类的父类AbsListView类中setOnScrollListener方法描述:
官网文档原文:
public void setOnScrollListener (AbsListView.OnScrollListener l)
Added in
API level 1
Set the listener that will receive notifications every time the list scrolls.
Parameters
l | the scroll listener |
---|
public static interface
AbsListView.OnScrollListener
有几个参数:
int
SCROLL_STATE_FLING The user had previously been scrolling using touch and had performed a fling.
整型参数
SCROLL_STATE_FLING 用户之前已经使用触屏实现了一个滚动。也就是手指离开屏幕,但屏幕还在滚动
int
SCROLL_STATE_IDLE The view is not scrolling.
整型参数
SCROLL_STATE_IDLE 视图静止,空闲状态
int
SCROLL_STATE_TOUCH_SCROLL The user is scrolling using touch, and their finger is still on the screen
整型参数
SCROLL_STATE_TOUCH_SCROLL 用户的手指还在屏幕上,正在触屏滑动
此接口有两个回调方法。
public abstract void onScroll (AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
回调方法当列表或网格完成滚动触发,当滚动完成时被调用。
参数:
view:滚动的视图
firstVisibleItem:第一个可见项的index
visibleItemCount 可见项的数目
totalItemCount 在列表的Adapter项的数目
public abstract void onScrollStateChanged (AbsListView view, int scrollState)
回调方法:当列表或网格正在滚动时的回调方法。如果这个视图正在滚动,这个方法将在滚动的下一帧被渲染之前调用。
it will be called before any calls to
getView(int, View, ViewGroup)
. 这句应该说它会在getView方法之前被调用吧。
参数详解:
view:滚动的控件视图