Closed xcc410922911 closed 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); }
}`
看到其中一个回答,提到让前端通知是否滚动到顶部。这个稍微修改为自行通过webview监听滚动到顶部。(较少多端通信代码的困难)
`mRefreshLayout.setScrollBoundaryDecider(new ScrollBoundaryDecider() {
以下是监听webview滚动到顶部的代码: `public class ScrollWebView extends WebView {
}`