缩放 Flex 组件并调整其大小

发布于 2024-10-28 10:37:43 字数 366 浏览 5 评论 0原文

我有从 UIComponent 继承的自定义 Flex 组件(已编译,无法访问源代码)。它具有固定的宽高比例,并且可以缩放。如果我将其宽度和高度设置为 100%,它会尝试适应父级的大小,但它会保持宽高比例,因此如果它的比例不等于父级的比例,则在调整父级大小时,该组件附近可能会出现空白空间。 在此处输入图像描述

我需要的是使我的组件完全适合父组件的尺寸。有什么好的方法可以做到这一点吗?我可以监听父级的 resize 事件,并使用组件的 scaleXscaleY,但可能存在更好的方法来解决我的问题(任何财产?)。谢谢。

I have custom flex component inherited from UIComponent (compiled, no source code access). It has fixed width-to-height proportions and it's scalable. If I set its width and height to 100%, it's trying to fit parent's size, but it keeps width-to-height proportion, so if it's proportion does not equal parent's proportion, there can appear empty space near this component when resizing parent.enter image description here

What I need, is to fit my component completely to parent's size. Is there any nice way to do this? I could listen to parent's resize event, and play with component's scaleX and scaleY, but may be any better way exists to solve my problem (any property?). Thanks.

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

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

发布评论

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

评论(3

我们的影子 2024-11-04 10:37:43

一个很好的方法是使用 greensock AutoFitArea。
编码很简单,如下所示,

var area:AutoFitArea = new AutoFitArea(this, 50, 70, 300, 100);
area.attach(myImage, {scaleMode:ScaleMode.PROPORTIONAL_OUTSIDE, crop:true});

它将限制内部的任何内容从那里开始执行给定的尺寸(300,100),您只需更改区域的宽度即可将为您解决一切问题。

希望有帮助

A great way is to use greensock's AutoFitArea.
Coding is as simple as the following

var area:AutoFitArea = new AutoFitArea(this, 50, 70, 300, 100);
area.attach(myImage, {scaleMode:ScaleMode.PROPORTIONAL_OUTSIDE, crop:true});

which would constrain whatever is inside do the given dimensions (300,100) from there on out, you can just change the area's width and that will figure it all out for you.

hope it helps

对你再特殊 2024-11-04 10:37:43

就我个人而言,我要做的是将父级中的组件设置为宽度/高度 100%,然后在组件本身中,覆盖 updateDisplayList 函数(返回未缩放的宽度/高度),然后调整您想要的任何子级的大小根据该容器的宽度/高度显示。像这样的事情:

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
    if(this._child!= null)
    {
        if(unscaledWidth > unscaledHeight)
        {
            this._child.height = unscaledHeight;
            this._child.scaleX = this._video.scaleY;
        }else{
            this._child.width = unscaledWidth;
            this._child.scaleY = this._video.scaleX;
        }
    }
}

应该这样做。

Personally, what I would do is have the component within the parent set at width/height 100%, then within the component itself, override the updateDisplayList function (which returns the unscaled width/height) and then resize whatever children you're trying to display depending on the width/height of this container. Something like this:

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
    if(this._child!= null)
    {
        if(unscaledWidth > unscaledHeight)
        {
            this._child.height = unscaledHeight;
            this._child.scaleX = this._video.scaleY;
        }else{
            this._child.width = unscaledWidth;
            this._child.scaleY = this._video.scaleX;
        }
    }
}

Should do it.

つ可否回来 2024-11-04 10:37:43

组件应该保持其比例吗?如果没有,您可以像您所说的那样,侦听父级的调整大小事件并将宽度和高度设置为组件值。

如果组件应保持其比例,您可以调整组件背景的大小,使其适合父组件的大小,并分别调整组件内容的大小及其比例。

Should the component keep its proportion? If not, you could just, as you said, listen to the resize event of the parent and set the width and height to the components values.

If the component should keep its proportion you could resize the background of your component so that it fits the parents size and resize the content of you component with its proportion seperatly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文