When ScrollView nested webview, if you need to call WebView settextsise, there will be a large gap in the bottom, tried a lot of methods do not work, inadvertently found a solution, incredibly can, I was drunk, I didn't think of it at the beginning. Okay, here's the code.
First write a method to reset the webview height
@JavascriptInterfacepublic 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))); } );
Then inject JS into your webview to dynamically get the height of this HTML content.
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");}
When you call settextsize each time, you only need to
Webview.loadurl ("Javascript:MyApp.resize (Document.body.getBoundingClientRect (). Height)");
Re-call this sentence will be OK.
ScrollView with WebView, the ultimate solution for setting the WebView font size is to leave white below.