Recently to do a page, need to Scollview nested webview, how to nest, how to solve the focus and touch time conflict, online a lot of, here do not repeat
But found that webview from a highly high page load a very low height of the page, the height can not adapt, resulting in a large gap at the bottom, the solution found a lot, describe
1. Google does not recommend the use of WebView in ScrollView, but after all, it is unavoidable that the product needs
2. Each time you load a new URL, remove the old WebView, re-add a new webview to load the new URL, this scheme is feasible, but after all, not very good, inefficient
3. JS Injection
Mwebview.setwebviewclient (New Webviewclient () {@Overridepublic void onpagefinished (WebView view, String URL) { Mwebview.loadurl ("Javascript:App.resize (Document.body.getBoundingClientRect (). Height)"); Super.onpagefinished ( view, URL);}); Mwebview.addjavascriptinterface (This, "App");
@JavascriptInterfacepublic void Resize (final float height) {getactivity (). Runonuithread (New Runnable () {@ overridepublic void Run () {//toast.maketext (getactivity (), Height + "", Toast.length_long). Show (); Mwebview.setlayoutparams (New Linearlayout.layoutparams (Getresources (). Getdisplaymetrics (). WidthPixels, (int) ( Height * getresources (). Getdisplaymetrics (). density)));});
Remember that the Resize method must be written above, written
Mwebview.getlayoutparams (). Height = (int) (Height * getresources (). Getdisplaymetrics (). density);
This is not successful, it seems that the width is also influential
There are other solutions on the web that I tried and couldn't succeed
4. When loading a low page from a high page, load an empty content, then immediately do the relevant processing (such as loading new pages, changing fonts, etc.),
Load empty data to shrink the WebView instancemarticlewebview.loadurl (constants.assets_empty);//Load Real DATAMARTICL Ewebview.loaddatawithbaseurl (NULL, data, "text/html", "Utf-8", null);
Constants.assets_empty is just a string substring that identifies the location of the empty page, so the variable can be "file:///android_asset/Empty.html".
Try, it is not good to use, do not know from time to time my operational problems, the original link http://vision-apps.blogspot.hk/2012/08/android-webview-tips-tricks.html
5. Modifying the Setting property
Wv.getsettings (). Setlayoutalgorithm (WebSettings.LayoutAlgorithm.SINGLE_COLUMN); Wv.setverticalscrollbarenabled ( FALSE); Wv.setverticalscrollbaroverlay (false); wv.sethorizontalscrollbarenabled (false); Wv.sethorizontalscrollbaroverlay (FALSE);
As bad as the original link http://blog.csdn.net/wht3xr/article/details/21004053
6. Some people's discussion: Http://stackoverflow.com/questions/15546416/how-to-shrink-webview-size-dynamically-according-to-its-content
Summing up, the 3rd method is still more useful, if the great God has other solutions, I hope to tell me
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Scollview nested WebView bottom blank, height not adaptive resolution