Skip to content Skip to sidebar Skip to footer

Detect If Webview Scroll Reach The End

am trying to figure out the max scroll position that the WebView can reach, i've tried the webView.pageDown(true) but the result is delayed ( i cant scroll it down, then up infront

Solution 1:

ok, i figured out the answer

you can get the real content height using

(int) Math.floor(webView.getContentHeight() * webView.getScale());

when you get the real height, then just override the scroll method in webview to listen to scroll event, if the scroll reach the real height, your webview is in the bottom of the scroll.

Solution 2:

@Override
publicvoidonScroll(int l, int t){
    int height = (int) Math.floor(webView.getContentHeight() * webView.getScale());
    int webViewHeight = webView.getHeight();
    int cutoff = height - webViewHeight - 10; // Don't be too strict on the cutoff pointif (t >= cutoff) {
        setDisclaimerButtonEnabled(true);
    }
}

The non-strictness is required, is because I found on the Samsung S5 the bottom most scroll value was only 1 pixel value away from the bottom most value!

Solution 3:

Loading / Visible button only when webview reached / scrolled to bottom.

Create JavaScript class :

publicclassJavaScriptInterface {

  @android.webkit.JavascriptInterfacepublicvoiddidScrollToBottom() {
    Log.d(TAG, "Scroll to Bottom");
    myHandler.post(newRunnable() {
      @Overridepublicvoidrun() {
         btnAccept.setVisibility(View.VISIBLE);

          }
       });
      }
    }

In onCreate() :

finalJavaScriptInterfacejsInterface=newJavaScriptInterface();
myWebView.addJavascriptInterface(jsInterface, "AndroidFunction");

Post a Comment for "Detect If Webview Scroll Reach The End"