title: WebView get maximum scroll width
body: <p>Hello guys i am creating epub reader and loaded the book in android webview
  and also made webview to move horizontally refering <a href="https://stackoverflow.com/questions/36617345/use-horizontal-scroll-in-android-webview/36628228?noredirect=1#comment67688154_36628228">this</a>
   but now i want to make webview to move like pages so i want to do this way
  1.calculate the total horizontalscroll width and screen width ,  now divide them to get total pages
  2.lock the scroll of webview and when ever user swipes ,set the scrolling of webview to screenwidth*swipeCount</p>
  
  <p>now the problem is when i am trying to get totalHorizontalScrollWidth  it is giving screen width i tried these ways but both giving same result</p>
  
  <p>FirstMethod</p>
  
  <pre><code>    ViewTreeObserver vto = webView.getViewTreeObserver();
      vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
              webView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
  
              Log.e("ScrollWidth",""+webView.getMeasuredWidth());
              Toast.makeText(getApplicationContext(), "new Width is"+webView.getMeasuredWidth(), Toast.LENGTH_SHORT).show();
          }
      });
  </code></pre>
  
  <p>returning  480 screen width </p>
  
  <p>and SecondMethod</p>
  
  <pre><code>public class WebViewWidth extends WebView {
  public WebViewWidth(Context context) {
      super(context);
  }
  public WebViewWidth(Context context, AttributeSet attrs) {
      super(context, attrs);
  }
  
  
  public int getContentWidth()
  {
      return this.computeHorizontalScrollRange();
  }
  public int getContentHeight()
  {
      return this.computeVerticalScrollRange();
  }
  }
  </code></pre>
  
  <p>and used this webView to get computeHorizontalScrollRange like this</p>
  
  <pre><code>private class MyWebViewClient extends WebViewClient {
  
  private Context mContext;
  
  
  public MyWebViewClient(Context context) {
      this.mContext = context;
  }
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
      return true;
  }
  
  @Override
  public void onPageFinished(WebView view, String url) {
      mProgressDialog.dismiss();
  
      final WebView myWebView = (WebView) view;
  
  
  
      String varMySheet = "var mySheet = document.styleSheets[0];";
  
      String addCSSRule = "function addCSSRule(selector, newRule) {"
              + "ruleIndex = mySheet.cssRules.length;"
              + "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);"
  
              + "}";
  
      String insertRule1 = "addCSSRule('html', 'padding: 0px; height: "
              + (myWebView.getMeasuredHeight() / mContext.getResources().getDisplayMetrics().density)
              + "px; -webkit-column-gap: 0px; -webkit-column-width: "
              + myWebView.getMeasuredWidth() + "px;')";
  
  
      myWebView.loadUrl("javascript:" + varMySheet);
       myWebView.loadUrl("javascript:" + addCSSRule);
      myWebView.loadUrl("javascript:" + insertRule1);
  
  
      super.onPageFinished(view, url);
   int widthis =  webView.getContentWidth();
  
      Toast.makeText(getApplicationContext(), "Width is"+widthis, Toast.LENGTH_SHORT).show();
      Log.i("WidthTotoal Scroll", ""+widthis);
  
   }
   }
  </code></pre>
  
  <p>Even this gives the result as 480 which is the screen size</p>
  
  <p>i also came across this script but dont know how to get values from this script to android</p>
  
  <pre><code> String js = ""+
      "var desiredHeight;"+
     " var desiredWidth;"+
     " var bodyID = document.getElementsByTagName('body')[0];"+
     " totalHeight = bodyID.offsetHeight;"+
      "pageCount = Math.floor(totalHeight/desiredHeight) + 1;"+
     " bodyID.style.padding = 10;"+ //(optional) prevents clipped letters around the edges
    "  bodyID.style.width = desiredWidth * pageCount;"+
     " bodyID.style.height = desiredHeight;"+
     " bodyID.style.WebkitColumnCount = pageCount;"; 
  </code></pre>
  
  <p>some one please help me to get the maximum horizontal scroll width of webview or some alternative to get effect like turning pages.</p>