Mohammad Ersan
Mohammad Ersan

Reputation: 12444

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 of the user, and this method doesn't work every time), i've tried also webView.getContentHeight() and the height isn't correct for Arabic content.

Please Advice

Upvotes: 9

Views: 18480

Answers (3)

Meanman
Meanman

Reputation: 1544

@Override
public void onScroll(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 point
    if (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!

Upvotes: 8

Satya
Satya

Reputation: 513

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

Create JavaScript class :

public class JavaScriptInterface {

  @android.webkit.JavascriptInterface
  public void didScrollToBottom() {
    Log.d(TAG, "Scroll to Bottom");
    myHandler.post(new Runnable() {
      @Override
      public void run() {
         btnAccept.setVisibility(View.VISIBLE);

          }
       });
      }
    }

In onCreate() :

final JavaScriptInterface jsInterface = new JavaScriptInterface();
myWebView.addJavascriptInterface(jsInterface, "AndroidFunction");

Upvotes: -1

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

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.

Upvotes: 17

Related Questions