积极答复者
windows 8 App,采用HTML5和JS开发,无法获取屏幕大小

问题
答案
-
HI there,
这里有篇文章我觉得应该对你会很有用,你可以看看:http://msdn.microsoft.com/zh-cn/library/windows/apps/hh465338.aspx 其中有提到你说的东西:
如果通过侦听 onresize 事件来对齐应用或旋转设备,则延长的初始屏幕应调整其初始屏幕图像的坐标。这有助于确保你的应用的加载体验看起来顺畅且专业,而无论你的用户如何操作其设备或在其屏幕上更改应用的布局。
这里你可以参考这个教程来实现目的:http://msdn.microsoft.com/zh-cn/library/windows/apps/hh700390.aspx
另外我这里暂时还没有win8.1的测试环境,不过我会对你说的问题进行测试,如果出现你所说的情况,我会提交给微软。
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Jamles HezModerator 2013年8月7日 4:32 更新
- 已标记为答案 Jamles HezModerator 2013年8月14日 5:48
全部回复
-
Hi 陆存璐,
你能share一下你的project么?因为在我这里做测试的时候一切都是正常的,我的代码如下:
首先注册一个OnResize的事件
window.addEventListener("resize", onResize);
然后对应的resize的事件里面代码:
function onResize(eventArgs) { // Update view for the new window size updateView(); var appWidth = eventArgs.view.outerWidth; wideLabel.innerHTML = appWidth; }
我全屏的时候是1600,Snap状态下为320,拉回至全屏的时候仍旧是1600,并没有你所说的无法获取屏幕大小的情况发生,请检查是否事件没有被触发或者别的什么原因。
另外你可以参考http://blogs.msdn.com/b/windowsappdev_cn/archive/2012/04/25/getting-your-pixels.aspx 这篇blog来规划自己的应用的视图变化。
我做测试用的代码是基于这个例子。如果你有疑问,可以告知我,多谢对论坛的支持。
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Jamles HezModerator 2013年8月6日 2:38 更新Blog
-
HI there,
这里有篇文章我觉得应该对你会很有用,你可以看看:http://msdn.microsoft.com/zh-cn/library/windows/apps/hh465338.aspx 其中有提到你说的东西:
如果通过侦听 onresize 事件来对齐应用或旋转设备,则延长的初始屏幕应调整其初始屏幕图像的坐标。这有助于确保你的应用的加载体验看起来顺畅且专业,而无论你的用户如何操作其设备或在其屏幕上更改应用的布局。
这里你可以参考这个教程来实现目的:http://msdn.microsoft.com/zh-cn/library/windows/apps/hh700390.aspx
另外我这里暂时还没有win8.1的测试环境,不过我会对你说的问题进行测试,如果出现你所说的情况,我会提交给微软。
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Jamles HezModerator 2013年8月7日 4:32 更新
- 已标记为答案 Jamles HezModerator 2013年8月14日 5:48
-
Hi
我早上做了一下测试,环境为8.1版本的VS2012和VS2013。
先来说一下VS2013,测试的时候不管怎么拉动app,都会触发onResize这个事件,可以说是完美支持。所以如果你不是用的VS2013开发的话,建议升级。
其次就是VS2012,这里面的表现的确很奇怪,在拖动窗体中间的黑色分割栏的时候,如下图所示,从黑色拉动到红色地方的过程中使不会触发onResize事件的,到红色线的地方可以触发事件,原因在于代码监控了视图变化的状态,也就是Snap状态从小区域变到默认的大区域。
不过我还是会将问题反馈给微软,多谢对论坛的支持。
以上请参考。
James He
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已编辑 Jamles HezModerator 2013年8月9日 1:15 123