【发布时间】:2013-12-28 22:44:11
【问题描述】:
我正在编写一个 Phonegap (3.2) 应用程序,我采用 HTML5 画布,使其全屏显示,整个应用程序 UI 都在此画布上。
使用三星 Galaxy S4 (Android 4.3) 测试应用,应用的屏幕分辨率只有 360X640 而不是我想要的 1080X1920。
需要做什么才能使应用使用最大可能的屏幕分辨率?
我添加了屏幕截图 1) // 看起来不错,但分辨率不好
windowWidth = window.innerWidth; windowHeight = window.innerHeight;
2) // 占据屏幕的一小部分,其余部分为白色
windowWidth = window.outerWidth; windowHeight = window.outerHeight;
3) // 只有一小部分图片可见,就好像图片是 1080X1920 但屏幕“太小”了。
windowWidth = screen.width; 窗口高度 = 屏幕高度;
这是完整的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>PhoneGapTesting</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<!-- -->
<script type="text/javascript">
var windowWidth;
var windowHeight;
var canvasMain;
var contextMain;
var backgroundImage;
$(document).ready(function() {
windowWidth = window.innerWidth;
windowHeight = window.innerHeight;
//windowWidth = window.outerWidth; // Only 'window.innerWidth' + 'window.innerHeight' look OK but not max resolution
//windowHeight = window.outerHeight;
//windowWidth = screen.width;
//windowHeight = screen.height;
canvasMain = document.getElementById("canvasSignatureMain");
canvasMain.width = windowWidth;
canvasMain.height = windowHeight;
contextMain = canvasMain.getContext("2d");
backgroundImage = new Image();
backgroundImage.src = 'img/landscape_7.jpg';
backgroundImage.onload = function() {
contextMain.drawImage(backgroundImage, 0, 0, backgroundImage.width, backgroundImage.height, 0, 0, canvasMain.width, canvasMain.height);
};
$("#canvasSignatureMain").fadeIn(0);
})
</script>
</head>
<body scroll="no" style="overflow: hidden">
<center>
<div id="deleteThisDivButNotItsContent">
<canvas id="canvasSignatureMain" style="border:1px solid #000000; position:absolute; top:0;left:0;"></canvas><br>
</div>
</center>
</body>
</html>
谢谢。
【问题讨论】:
标签: html canvas cordova webview resolution