3
我有一個Fragment
,它有一個ScrollView
和一個SwipeRefreshLayout
。當ScrollView
不在頂部時,我想禁用SwipeRefreshLayout
,因此用戶可以再次在Fragment
的頂部滾動。我試圖創建一個自定義ScrollView
並重寫onScrollChanged
方法這樣當ScrollView不在頂部時禁用SwipeRefreshLayout
@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
但它沒有工作。
如果用戶不在ScrollView的頂部,用戶如何觸發刷新? – jimmy0251
他回到頂部並滑動。 –