【问题标题】:Disable SwipeRefreshLayout when the ScrollView is not on the top当 ScrollView 不在顶部时禁用 SwipeRefreshLayout
【发布时间】:2016-01-10 21:15:26
【问题描述】:

我有一个Fragment,其中有一个ScrollView 和一个SwipeRefreshLayout。当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() &lt;= 0 是否无效。

【问题讨论】:

  • 如果用户不在ScrollView的顶部,如何触发刷新?
  • 他回到顶部并滑动。

标签: android scrollview landscape swiperefreshlayout


【解决方案1】:

尝试使用NestedScrollView。

当需要在另一个滚动视图中使用滚动视图时使用此选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 2022-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 2018-02-25
    相关资源
    最近更新 更多