Android Oreo WebView renders layout too small after 2nd loading

牧云@^-^@ 提交于 2019-12-21 06:01:12

问题


On some Android Oreo devices, when I load an url on webview for the first time, the URL page loads properly. However, when I load the URL again, the page is zoomed out. On devices lower than android oreo, the page loads properly for all devices.

Also, when you kill the app on the background and load again, the URL loads properly. On the second and succeeding tries, it shows the zoomed out version again. I attached the images of loaded URL below

Below is the correct loading of webpage on the webview

Below is the small display of webpage on webview webview

Android XML Code:

<WebView
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Java Code:

    private WebView mWebView;
    mWebView = (WebView) view.findViewById(R.id.content_view);
    mWebView.loadUrl("https://policies.google.com/");

URL: https://policies.google.com/

Take note that this happen in other URLs too. https://policies.google.com/ is just an example

It works on the following: Huawei nova 2i RNE-L22, Android 8.0.0

It DOES NOT work on the following Android 8.1.0; Pixel 2 Android 8.0.0; Samsung SM-G950FD Android 8.0.1; Huawei P20 EML-L29

Any suggestions or reasons as why this happens? How to fix this?

Thanks in advance.


回答1:


if you have problems related to zoom in webview

try to add zoom in and zoom out functions to your webview

you can add these lines to your java code, to implement zooming in and out

mWebView.loadUrl(url);
//code for zooming functions
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setSupportZoom(true);
//for javascript
webView.getSettings().setJavaScriptEnabled(true);



回答2:


After asking google team about this issue, the said that it's probably some viewport layout settings. Webview has some unfortunate defaults due to legacy issues.,

Adding webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); fixed the issue.



来源:https://stackoverflow.com/questions/51784469/android-oreo-webview-renders-layout-too-small-after-2nd-loading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!