原:http://www.easymorse.com/index.php/archives/1605
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(final AbsListView view, int scrollState) {
switch (scrollState) {
case AbsListView.OnScrollListener.SCROLL_STATE_FLING:
Log.e(“tag”, “SCROLL_STATE_FLING”);
break;
case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
Log.e(“tag”, “SCROLL_STATE_IDLE”);
int firstPostion = view.getFirstVisiblePosition();
View firstChild = view.getChildAt(0);
final int height = firstChild.getHeight();
final int top = -(firstChild.getTop());
if (top > (height / 2)) {
Log.e(“tag”, “firstPostion = ” + firstPostion);
// view.smoothScrollToPosition(firstPostion + 1);
view.post(new Runnable() {
@Override
public void run() {
view.smoothScrollBy(height – top, 200);
}
});
} else {
view.post(new Runnable() {
@Override
public void run() {
view.smoothScrollBy(-top, 200);
}
});
}
Log.e(“tag”, “top = ” + top);
Log.e(“tag”, “height = ” + height);
break;
case AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
Log.e(“tag”, “SCROLL_STATE_TOUCH_SCROLL”);
break;
default:
break;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {}
});