检测 ScrollView 的顶部
Detect the top of a ScrollView
如何检测 ScrollView 的顶部?我已经实现了检测底部的代码,但我似乎无法弄清楚确定顶部何时出现的计算达到。
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
int startPosition = t;
View view = (View) getChildAt(getChildCount() - 1);
int diff = (view.getBottom() - (getHeight() + getScrollY()));
if (diff == startPosition){
oListener.onTopReached();
} else {
nListener.BottomNotReached();
}
/* if (diff == 0 && mListener != null) {
mListener.onBottomReached();
} else if (diff == getTop()) {
oListener.onTopReached();
} else {
nListener.BottomNotReached();
}*/
super.onScrollChanged(l, t, oldl, oldt);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
if(view.getTop()==t){
// reaches the top end
}
View view = (View) getChildAt(getChildCount()-1);
int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff
if( diff <= 0 ){
// if diff is zero, then the bottom has been reached
Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
}
super.onScrollChanged(l, t, oldl, oldt);
}
如何检测 ScrollView 的顶部?我已经实现了检测底部的代码,但我似乎无法弄清楚确定顶部何时出现的计算达到。
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
int startPosition = t;
View view = (View) getChildAt(getChildCount() - 1);
int diff = (view.getBottom() - (getHeight() + getScrollY()));
if (diff == startPosition){
oListener.onTopReached();
} else {
nListener.BottomNotReached();
}
/* if (diff == 0 && mListener != null) {
mListener.onBottomReached();
} else if (diff == getTop()) {
oListener.onTopReached();
} else {
nListener.BottomNotReached();
}*/
super.onScrollChanged(l, t, oldl, oldt);
}
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
if(view.getTop()==t){
// reaches the top end
}
View view = (View) getChildAt(getChildCount()-1);
int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff
if( diff <= 0 ){
// if diff is zero, then the bottom has been reached
Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
}
super.onScrollChanged(l, t, oldl, oldt);
}