我有一个包含ScrollView
和SwipeRefreshLayout
的Fragment
。当ScrollView
不在顶部时,我想禁用SwipeRefreshLayout
,这样用户就可以再次滚动到Fragment
的顶部。我尝试创建一个自定义的ScrollView
并重写onScrollChanged
方法,如下所示:
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
View view = (View) getChildAt(getChildCount() - 1);
int d = view.getBottom();
d -= (getHeight() + getScrollY());
if (d <= 0) {
// bottom
} else if (getScrollY() <= 0) {
// top
swipeRefreshLayout.setEnabled(true);
} else {
swipeRefreshLayout.setEnabled(false);
super.onScrollChanged(l, t, oldl, oldt);
}
}
这在竖屏模式下可以正常工作,但在横屏模式下就不行了。我还尝试检查
getScrollX() <= 0
是否可行,但没有成功。