试图在所有API
问题描述:
我使用的是接下来的源代码,以向上滚动,滚动型向上滚动滚动型,但我已经看到,该方法removeOnGlobalLayoutListener没有受到API 16试图在所有API
public void scrollUp(){
// Wait until my scrollView is ready
sv_container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Ready, move up
sv_container.fullScroll(View.FOCUS_UP);
sv_container.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
兼容您是否知道在所有API中实现此目的的方法?谢谢
答
答
解决:
public void scrollUp(){
// Wait until my scrollView is ready
sv_container.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// Ready, move up
sv_container.fullScroll(View.FOCUS_UP);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
sv_container.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
sv_container.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
}
好的,谢谢。通过你的回答我已经做了一个解决方案。 – MAOL 2014-09-19 09:13:50