Mine is a native app where I want to show/ hide a button if the user scrolls to the end of webview. I looked at an answer here and got the entire idea of how to register the callback via interface. My major issue is that I am not able to get my calculations right inside the onScrollChanged method. I have tried combination of things like getHeight(), getContentHeight(), top etc but it just seems to fire too early. I tried with a simple page like google's with comparatively lesser content as well as a news page.
These logics work fine for a normal scroll view. Since the webpage has a lot of content, it could be messing up the calculations. Pasting a sample code: does not work.
@Override
protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) {
if ( mOnWebViewBottomReachedListener != null ) {
//if ( (getContentHeight() - (top + getHeight())) <= mMinDistance )
int diff = (getBottom() - (getHeight() + getScrollY()));
Log.e("values ", diff+" o");
if ((int) Math.floor(getContentHeight() * getScaleY()) == top)
mOnWebViewBottomReachedListener.onBottomReached(this);
}
super.onScrollChanged(left, top, oldLeft, oldTop);
}
Need help with this. Thanks.
After a lot of google search all the solutions I found were calculating the height and determining the scrollOfset, but most of them are not reliable in most cases resulting in issues like described here Weird miscalculation when trying to detect if WebView scrolled to bottom
I have found the solution that works 100% is to determine it based on overScroll
webView.setOnOverScrolledCallback(new WebViewCustom.OnOverScrolledCallback() {
@Override
public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
if(clampedY)
if(scrollY == 0) {
//top
}
else {
//bottom
}
}
});
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