首页 > 解决方案 > Android WebView Canvas 随机无法使用不同的宽度和高度

问题描述

对于以下测试,我使用了以下 HTML 片段,我使用了在线 HTML 编辑器和 Android-Emulator 中的 Android-WebView-Tester,屏幕为 9.7"。

此代码运行良好(Android-Webview-Tester 的图像

var canvas = document.getElementById("myCanvas");

//canvas.setAttribute("height", "500");
 ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>

此代码在浏览器上运行良好,但在 Android-Emulator 中运行良好(Android-Emulator 的图像不工作)

var canvas = document.getElementById("myCanvas");

//canvas.setAttribute("height", "500");
 ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
<canvas id="myCanvas" width="800" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the canvas element.
</canvas>

这是一个已知问题吗?我错过了什么?我使用的是安卓 8.1

我对 Android-Chrome-Browser 没有任何问题,但我正在构建一个具有完全相同问题的 Cordova-App。Chrome-Webinspector 不会给出任何错误/警告。

标签: javascriptandroidcanvasandroid-webview

解决方案


推荐阅读