问题
How can i detect how much a scroll view has scrolled ?
回答1:
You need to override the onScrollChanged()
method of the ScrollView:
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
Log.i(TAG, "View onScrollChanged");
View view = (View) getChildAt(getChildCount() - 1);
int diff = (view.getBottom() - (getHeight() + getScrollY()));// Calculate
super.onScrollChanged(l, t, oldl, oldt);
}
Here, diff
is the space left for scrolling between the bottom edge of the ScrollView
, and the currently visible content at the bottom. When diff = 0
, the ScrollView
has been scrolled down fully.
来源:https://stackoverflow.com/questions/12543495/how-to-detect-how-much-the-view-has-scroll-scrollview