Flex4 网页Application界面大小自适应屏幕
2014-06-27 12:04
441 查看
首先是按照常规思维在app中设置
这样确实可以全屏,但是当屏幕缩放到小于1280*720时,浏览器并不会自动添加滚动条,所以网页超出屏幕大小的内容就看不到了。
为了解决不出现滚动条,在网上找到了答案,并成功解决
http://stackoverflow.com/questions/4259434/flex-4-sscroll
设置Application的height和width属性,不设置minHeight和minWidth,当屏幕小于height和width时出现滚动条。
但是,这种方法可以实现滚动条,但是必须是设定height和width的固定大小,也就是说当我的屏幕大于这个设定的固定大小时,浏览器重显示的网页也只有width*height大,会出现空白区域,所以还是不能满足自适应的要求。
最终的解决方案是:
<http://wbgen.com/blog/flex4%E8%AE%A9%E6%B5%8F%E8%A7%88%E5%99%A8%E7%AA%97%E5%8F%A3%E5%B0%8F%E4%BA%8Eapplication%E5%A4%A7%E5%B0%8F%E6%97%B6%E5%87%BA%E7%8E%B0%E6%BB%9A%E5%8A%A8%E6%9D%A1>
在index.template.html文件(位于Flex项目文件中的html-template文件夹下)中添加js脚本,实现读取当前屏幕大小,判断获取的屏幕width小于1280px时width取1280px,当大于时,width去获取的屏幕width,height的设置方法也是这样。
然后在Flex中App中设置
这样即可实现自适应的同时设定网页的最小width和height。
在ie8中,“开发人员工具”中“脚本”中就可以看到这个index.template.html文件了,所以flex网页最终也是以html形式存在,flex生成的swf网页只是html中的一个object
为了确保万无一失,我将index.template.html中object的width和height都设成100%。
<mxml> <s:Application ....... width="100%" height="100%" minWidth="1280" minHeight="720">
这样确实可以全屏,但是当屏幕缩放到小于1280*720时,浏览器并不会自动添加滚动条,所以网页超出屏幕大小的内容就看不到了。
为了解决不出现滚动条,在网上找到了答案,并成功解决
http://stackoverflow.com/questions/4259434/flex-4-sscroll
设置Application的height和width属性,不设置minHeight和minWidth,当屏幕小于height和width时出现滚动条。
但是,这种方法可以实现滚动条,但是必须是设定height和width的固定大小,也就是说当我的屏幕大于这个设定的固定大小时,浏览器重显示的网页也只有width*height大,会出现空白区域,所以还是不能满足自适应的要求。
最终的解决方案是:
<http://wbgen.com/blog/flex4%E8%AE%A9%E6%B5%8F%E8%A7%88%E5%99%A8%E7%AA%97%E5%8F%A3%E5%B0%8F%E4%BA%8Eapplication%E5%A4%A7%E5%B0%8F%E6%97%B6%E5%87%BA%E7%8E%B0%E6%BB%9A%E5%8A%A8%E6%9D%A1>
在index.template.html文件(位于Flex项目文件中的html-template文件夹下)中添加js脚本,实现读取当前屏幕大小,判断获取的屏幕width小于1280px时width取1280px,当大于时,width去获取的屏幕width,height的设置方法也是这样。
var winWidth = 0; var winHeight = 0; function findDimensions() { //获取窗口宽度 if (window.innerWidth) { winWidth = window.innerWidth; } else if ((document.body) && (document.body.clientWidth)) { winWidth = document.body.clientWidth; //获取窗口高度 } if (window.innerHeight) { winHeight = window.innerHeight; } else if ((document.body) && (document.body.clientHeight)) { winHeight = document.body.clientHeight; } //通过深入Document内部对body进行检测,获取窗口大小 if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) { winHeight = document.documentElement.clientHeight; winWidth = document.documentElement.clientWidth; } var cssSize = document.styleSheets[0].rules||document.styleSheets[0].cssRules; if(winWidth < 1280) { cssSize[0].style.width = "1280px"; } else { cssSize[0].style.width = "100%"; } if(winHeight < 720) { cssSize[0].style.height = "720px"; } else { cssSize[0].style.height = "100%"; } } window.onresize=findDimensions; function pageInit() { //调用函数,获取数值 findDimensions(); }
然后在Flex中App中设置
width="100%" height="100%"
这样即可实现自适应的同时设定网页的最小width和height。
在ie8中,“开发人员工具”中“脚本”中就可以看到这个index.template.html文件了,所以flex网页最终也是以html形式存在,flex生成的swf网页只是html中的一个object
为了确保万无一失,我将index.template.html中object的width和height都设成100%。
<noscript> <span style="color:#ff0000;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="MainFx7"></span> <param name="movie" value="MainFx7.swf" /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <param name="allowScriptAccess" value="sameDomain" /> <param name="allowFullScreen" value="true" /> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="MainFx7.swf" width="100%" height="100%"> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <param name="allowScriptAccess" value="sameDomain" /> <param name="allowFullScreen" value="true" /> <!--<![endif]--> <!--[if gte IE 6]>--> <p> Either scripts and active content are not permitted to run or Adobe Flash Player version 10.0.0 or greater is not installed. </p> <!--<![endif]--> <a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" /> </a> <!--[if !IE]>--> </object> <!--<![endif]--> </object> </noscript>
相关文章推荐
- [转]如何设计自适应屏幕大小的网页 Responsive Web Design
- 使PC端网页宽度自适应手机屏幕大小
- 使PC端网页宽度自适应手机屏幕大小
- 自适应屏幕大小的网页
- 如何设计自适应屏幕大小的网页
- 用CSS3的@media属性根据屏幕大小做自适应各种分辨率网页显示版本-media_query详解
- 自适应网页里,字体大小如何自适应屏幕
- MFC 窗口最大化和最小化,全局变量的使用、static居中显示、static的背景色设置为透明、根据屏幕自适应调整界面大小
- 手机端网页所有内容根据屏幕大小自适应(大小,位置)
- 如何设计自适应屏幕大小的网页
- 如何设计自适应屏幕大小的网页
- 自适应屏幕大小的网页是怎么做出来的
- android控件根据屏幕大小自适应 分类: Android界面和组件 2014-07-01 20:12 94人阅读 评论(0) 收藏
- flex界面设计中根据用户屏幕的大小,需要设定应用程序界面的最小size 和最大size
- JS获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度
- android自适应屏幕方向和大小
- 修改LINUX字符界面屏幕的大小
- android自适应屏幕方向/大小/分辨率
- JS获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度(转)
- JS获取浏览器窗口大小 获取屏幕,浏览器,网页高度宽度