8

我想用内置的缩放功能在 WebView 中显示一些 HTML 内容。在某些情况下它非常好,但有时 HTML 内容在放大和缩小时会被切断。

val settings = webview.settings
settings.loadsImagesAutomatically = true
settings.javaScriptEnabled = true
settings.setSupportZoom(true)
settings.builtInZoomControls = true
settings.displayZoomControls = false
webview.loadDataWithBaseURL("file:///android_asset/", onlyHtmlString, "text/html", "utf-8", null)

这是我的简单 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
        
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

当 WebView 内容被切断时,我遇到了错误

I/chromium: [INFO:SkTypeface_remote.cpp(29)] GlyphCacheMiss generateMetrics: Rec
      textsize 162 prescale 1 preskew 0 post [1 0 0 1]
      frame -1 miter 0 format 1 join 0 cap 0 flags 0x3104
      lum bits ff000000, device gamma 64, paint gamma 64 contrast 0

在此处输入图像描述

4

1 回答 1

0

尝试添加settings.loadWithOverviewMode = truesettings.useWideViewPort = true

于 2022-01-12T12:16:23.680 回答