0

In my android webview I am able to scrolling outside of web content. I want to disable that. Is that possible? Same applies and for all sides and bottom. I want to scroll my page of course but I want to disable only this scrolling distances.

enter image description here

IntoTheDeep
  • 4,027
  • 15
  • 39
  • 84

1 Answers1

1

Following code will help you to fit the content of Webview with the view:

private void setupWebView() {
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {


        webView.loadUrl("javascript:MyApp.resize(document.body.getBoundingClientRect().height)");
                super.onPageFinished(view, url);
            }
        });
        webView.addJavascriptInterface(this, "MyApp");
    }

    @JavascriptInterface
    public void resize(final float height) {
        MyActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                webView.setLayoutParams(new LinearLayout.LayoutParams(getResources().getDisplayMetrics().widthPixels, (int) (height * getResources().getDisplayMetrics().density)));
            }
        });
    }
Anjali
  • 1
  • 1
  • 13
  • 20