Can Android's WebView automatically resize huge images?

前端 未结 8 1851
心在旅途
心在旅途 2020-11-28 05:41

In some web browsers, huge images are automatically resized to fit the screen.

Is it possible to do the same in an Android WebView?

The web page just contain

8条回答
  •  我在风中等你
    2020-11-28 06:22

    webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
    

    works but is deprecated. This is another solution without LayoutAlgorithm.SINGLE_COLUMN, using CSS:

    @SuppressLint("NewApi")
    private openWebView() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.TEXT_AUTOSIZING);
        } else {
            webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
        }
        String data = "
    your HTML content
    "; webView.loadDataWithBaseURL("file:///android_asset/", getHtmlData(data), "text/html", "utf-8", null); } private String getHtmlData(String bodyHTML) { String head = ""; return "" + head + "" + bodyHTML + ""; }

提交回复
热议问题