scwang90 / SmartRefreshLayout

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。
https://segmentfault.com/a/1190000010066071
Apache License 2.0
24.95k stars 4.96k forks source link

webview滚动,下拉失效问题(已解决) #1548

Closed xcc410922911 closed 11 months ago

xcc410922911 commented 11 months ago

`mRefreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider() {

        @Override
        public boolean canRefresh(View content) {
            return isScrollTop;
        }

        @Override
        public boolean canLoadMore(View content) {
            return false;
        }
    });
    mWebView.setOnScrollToTopListener((isScrollToTop) -> {
        isScrollTop = isScrollToTop;
    });`

以下是监听webview滚动到顶部的代码: `public class ScrollWebView extends WebView {

private OnScrollToTopListener onScrollToTopListener;

public ScrollWebView(Context context) {
    super(context);
}

public ScrollWebView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ScrollWebView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

public void setOnScrollToTopListener(OnScrollToTopListener listener) {
    this.onScrollToTopListener = listener;
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);

    if (t == 0 && onScrollToTopListener != null) {
        onScrollToTopListener.onScrollToTop(true);
    } else {
        onScrollToTopListener.onScrollToTop(false);
    }
}

public interface OnScrollToTopListener {
    void onScrollToTop(boolean isScrollToTop);
}

}`

xcc410922911 commented 11 months ago

看到其中一个回答,提到让前端通知是否滚动到顶部。这个稍微修改为自行通过webview监听滚动到顶部。(较少多端通信代码的困难)