limit scroll boundaries in webview

374 views Asked by At

I create simple app that contains webview and I present web content inside.

My question is, whether is it possible to limit scroll boundaries in that sense that we cannot go behind certain boundaries, for example if this is whole page, and it has height of 100 000 px, I would like to "skip" or to "cuts off" for example first 1000 px, and when user scrolls up and down, to put limitations, and not to allow them to cross over a certain limit, in my case limit is on the top and I don't want to show first part of the page.

this is how it loads now                 and this is how it should be loaded 
                                                     and "locked" 
--------------------------------           -------------------------------- 
|                              |           |  ___                         |
|                              |           |  ___ this is hamburger menu  |
|    part to skip over         |           |  ___                         |
|                              |           |                              |
|this line represents boundary |           |                              |
|I do not want to cross when   |           |                              |
|     users scrolls up         |           |                              |
| ---------------------------  |           |                              |
|                              |           |                              |
|  ___                         |           |                              |
|  ___ this is hamburger menu  |           |                              |
|  ___                         |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
|                              |           |                              |
--------------------------------           --------------------------------
             .                                              .
             .                                              .
             .                                              .
     rest of web page                               rest of web page

I have tried with

mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

//view.scrollTo(0,70);   //puts me on good position on webpage, problem, does not create the boundary beyond which it can not be passed
//view.setScrollY(70);   //puts me on good position on webpage, problem, does not create the boundary beyond which it can not be passed
//view.setTop(-70);  //setPadding    this is good in because it create limits on the top, but it cut off hamburger menu bar
//view.setY(-70);    //setPadding    this is good in because it create limits on the top, but it cut off hamburger menu bar
//view.scrollBy(0,999);       //this just goes to certain height but dont put boundaries to the top which it cannot be passed

And I even found interesting idea on this link because I tried to override behavior of WebView link2, but in my CustomWebView I did this

protected int computeVerticalScrollRange(WebView view) {
    int heighy1 = view.getHeight()  - 1000;
    return super.computeVerticalScrollRange() - heighy1;
}

and when I call inside of public void onPageFinished(WebView view, String url)

mWebView.computeVerticalScrollRange(view);

nothing happens, and maybe I didn't do something right.

I didn't find solution to my problem anywhere.

Thanks in advance!!!

I appreciate any kind of help.

0

There are 0 answers