android 偵測scroll事件的寫法
myLastVisiblePos放在全域變數
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int myLastVisiblePos; | |
gridView.setOnScrollListener(new AbsListView.OnScrollListener() { | |
@Override | |
public void onScrollStateChanged(AbsListView view, int scrollState) { | |
if(scrollState ==AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) | |
{ | |
//scroll start | |
} | |
if(scrollState ==AbsListView.OnScrollListener.SCROLL_STATE_IDLE) | |
{ | |
//stop | |
} | |
} | |
@Override | |
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { | |
int currentFirstVisPos = view.getFirstVisiblePosition(); | |
if(currentFirstVisPos > myLastVisiblePos) { | |
//scroll down | |
} | |
if(currentFirstVisPos < myLastVisiblePos) { | |
//scroll up | |
} | |
myLastVisiblePos = currentFirstVisPos; | |
} | |
}); |
留言
張貼留言