我正在使用下一个源代码向上滚动滚动视图,但我看到方法removeOnGlobalLayoutListener在API 16下不兼容。
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中实现此目的的方法?感谢
答案 0 :(得分:1)
请确保在可用的地方使用新的。
答案 1 :(得分:0)
<强>解决:强>
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);
}
}
});
}