屏幕分辨率太小时如何缩放Flex应用程序?

发布于 2024-10-23 23:10:21 字数 317 浏览 1 评论 0原文

我正在开发一个 Flex 应用程序,专为 1280x1024 及更高的屏幕分辨率而设计。在使用投影仪的极少数情况下(通常最大为 1024x768 像素),我想缩小应用程序(目前我有很多滚动条和剪辑)。

我已经尝试过应用程序的属性 scaleXscaleY 以及 stage.scaleMode。 我无法完全找到一种在不缩放的情况下渲染应用程序的方法。

  • 但是,当应用程序的宽度和高度大于某些值时,
  • 当宽度或高度小于某些值时,

我该如何实现这一点?

I'm developing a Flex application that is designed for screen resolutions of 1280x1024 and more. In the rare case that a projector is used (which usually has a maximum of 1024x768 pixels) I'd like to scale down the application (currently I get lots of scrollbars and clipping).

I've already experimented with the application's properties scaleX and scaleY as well as stage.scaleMode. However, I couldn't quite figure out a way to

  • render the application without scaling when the application's width and height are larger than certain values
  • use scaling when the width or height are smaller than certain values

How can I accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

明月松间行 2024-10-30 23:10:22

我终于找到了一种缩小应用程序规模的方法。事实上,孩子们需要扩展的应用程序。否则应用程序的宽度高度会缩小。

由于我使用的是状态,因此我还必须为 currentStateChanging 事件添加一个事件处理程序。

private static const MIN_WIDTH:Number = 1250;
private static const MIN_HEIGHT:Number = 800;

protected function application_currentStateChangingHandler():void
{
    callLater(scaleElements);
}

protected function application_resizeHandler():void
{
    scaleElements();
}

protected function scaleElements():void
{
    var newScaleX:Number = 1;
    var newScaleY:Number = 1;

    if (width < MIN_WIDTH)
        newScaleX = width / MIN_WIDTH;

    if (height < MIN_HEIGHT)
        newScaleY = height / MIN_HEIGHT;

    var newScale:Number = Math.min(newScaleX, newScaleY);

    for (var i:int = 0; i < numElements; i++)
    {
        var element:DisplayObject = getElementAt(i) as DisplayObject;

        if (element)
        {
            element.scaleX = newScale;
            element.scaleY = newScale;
        }
    }
}

I finally figured out a way to scale down the application. Actually, the applications children need to scale. Otherwise the width and height of the application shrinks.

Since I'm using states I had to add an event handler for the currentStateChanging event too.

private static const MIN_WIDTH:Number = 1250;
private static const MIN_HEIGHT:Number = 800;

protected function application_currentStateChangingHandler():void
{
    callLater(scaleElements);
}

protected function application_resizeHandler():void
{
    scaleElements();
}

protected function scaleElements():void
{
    var newScaleX:Number = 1;
    var newScaleY:Number = 1;

    if (width < MIN_WIDTH)
        newScaleX = width / MIN_WIDTH;

    if (height < MIN_HEIGHT)
        newScaleY = height / MIN_HEIGHT;

    var newScale:Number = Math.min(newScaleX, newScaleY);

    for (var i:int = 0; i < numElements; i++)
    {
        var element:DisplayObject = getElementAt(i) as DisplayObject;

        if (element)
        {
            element.scaleX = newScale;
            element.scaleY = newScale;
        }
    }
}
鼻尖触碰 2024-10-30 23:10:22

为了扩展整个应用程序,而不是单独扩展所有元素,我删除了循环并添加了:

this.scaleX = newScale;
this.scaleY = newScale;

To scale the application as a whole, and not all the elements separately, I removed the loop and added instead:

this.scaleX = newScale;
this.scaleY = newScale;
两仪 2024-10-30 23:10:22

Alex Harui 在 2009 年提出了一个很好的解决方案。请参阅 ScaleMode 自动缩放应用程序。请参阅此处示例,了解其工作原理。

A nice solution was presented back in 2009 by Alex Harui. See ScaleMode to scale application automatically. See example here how it works.

怕倦 2024-10-30 23:10:21

我将通过向顶级应用程序上的“调整大小”事件添加事件侦听器来解决此问题。下面是调整大小事件的示例方法处理程序(假设处理程序位于主 Application 类中,因此“this”指的是顶级应用程序):

function onResize(e:Event):void {
  if(this.scaleX > 1){
    //check if we need to readjust to a normal scale of 1
    var effectiveWith:int = this.width*this.scaleX;
    var effectiveHeight:int = this.height*this.scaleY;
    if(effectiveWidth > 1280 || effectiveHeight > 1024){
        this.scaleX = 1;
        this.scaleY = 1;
    }
   }else{
    //the scale is still 1, lets see if we should scale it up
    if(this.width < 1280 || this.height < 1024){
        this.scaleX = (1280-this.width)/1280 + 1;
        this.scaleY = (1024-this.height)/1024 + 1;
    }
  }
}

I'd tackle this by adding an event listener to the "resize" event on the top level application. Here's an example method handler for the resize event (assumes the handler is in the main Application class, so "this" refers to the top level Application):

function onResize(e:Event):void {
  if(this.scaleX > 1){
    //check if we need to readjust to a normal scale of 1
    var effectiveWith:int = this.width*this.scaleX;
    var effectiveHeight:int = this.height*this.scaleY;
    if(effectiveWidth > 1280 || effectiveHeight > 1024){
        this.scaleX = 1;
        this.scaleY = 1;
    }
   }else{
    //the scale is still 1, lets see if we should scale it up
    if(this.width < 1280 || this.height < 1024){
        this.scaleX = (1280-this.width)/1280 + 1;
        this.scaleY = (1024-this.height)/1024 + 1;
    }
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文