Im trying to use the webview's scroll position to determine whether SwipeRefreshLayout should be able to refresh, except for some websites e.g. https://jobs.lever.co/memebox, getScrollY() always returns 0. Is there a way to ensure I will always get the correct scroll position?
Maybe you can try to add this to your custom webview
just tell it's scrolling
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
if(this.getScrollY() <= 0){
this.scrollTo(0,1);
}
break;
case MotionEvent.ACTION_UP:
break;
}
return super.onTouchEvent(event);
}
and then override onScrollChanged
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);;
if (iWebViewScrollListener != null && t == 0) {
iWebViewScrollListener .onTop();
} else if (mIWebViewScroll != null && t != 0) {
iWebViewScrollListener .notOnTop();
}
}
add an top listener call back when scrolling.When is onTop()
use setEnabled(true)
for SwipeRefreshLayout,else setEnabled(false)
The site you linked has a fixed header. My guess is that the page itself doesn't scroll; a container inside it does. The WebView
can't inspect every scrollable container on the page, so it sees that the top-level container doesn't scroll and assumes that the entire thing is fixed.
If all you need this for is pull-to-refresh, I'd recommend adding a refresh button in addition to the SwipeRefreshLayout
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With