Skip to content Skip to sidebar Skip to footer

Getting A Maximum Scroll Value Of A Webview

I know in Scrollview you can access scrollView.getMaxScrollAmount however I don't seem to understand how to call it on webview. I tried cheating to get the information about it. He

Solution 1:

A bit late, but if anyone needs the answer, webview has a protected method - computeVerticalScrollRange() - if you want to know the max scroll range you can override the WebView and return computeVerticalScrollRange() - getHeight()

Solution 2:

here you go: this is working perfectly for me (it scrolls to the end)

the trick is in using the function getContentHeight of WebView

package sherif.android.activity;

import sherif.android.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;

publicclassWebClientTestActivityextendsActivity {
    /** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        WebViewwebView=newWebView(this);
        StringUserAgent="User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; 
        //webView.getSettings().setUserAgentString(UserAgent); 
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.google.com/search?gcx=w&sourceid=chrome&ie=UTF-8&q=arsenal");
        webView.setWebViewClient(newWebViewClient(){
            @OverridepublicvoidonPageFinished(WebView view, String url) {
                Log.v("here","here");
                view.scrollBy(0, view.getContentHeight());
            }
        });
        setContentView(webView);
    }
}

Solution 3:

'WebView.canScrollVertically(int direction)'

also indicates whether it is still possible to scroll up/down.

intdirectionUp= -1;
intdirectionDown=1;
boolean canGoUp, canGoDown;
WebView webView1;
webView1 = ...

canGoUp = webView1.canScrollVertically(directionUp);
canGoDown = webView1.canScrollVertically(directionDown);

Post a Comment for "Getting A Maximum Scroll Value Of A Webview"