Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Here is what I tried.

What the method was suppose to do is that it continually scroll in a specific amount and checks if the value isn't increased in that amount it gets that amount and returns it with the max value. However it doesn't work.

public String scrollToMAX(){
        webView1.scrollTo(0, 0);
        Boolean istrue = true;
        String getIntData = "";
        int i = 0;
        while(istrue){
            int checker = webView1.getScrollY();
            if(i != checker){
                i = checker;
                getIntData = Integer.toString(i);
                istrue = false;
            }
            i=i+5000;
            webView1.scrollTo(0, i);
        }
        webView1.scrollTo(0, 0);
        return getIntData;
        //Put a return string here
    } 
like image 374
wesdfgfgd Avatar asked Nov 27 '22 22:11

wesdfgfgd


1 Answers

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()

like image 131
Nir Hartmann Avatar answered Dec 09 '22 18:12

Nir Hartmann