我正在编写一个 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;
windowHeight = screen.height;
以下是完整代码:
<!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>
谢谢。