缩放 Flex 组件并调整其大小
我有从 UIComponent 继承的自定义 Flex 组件(已编译,无法访问源代码)。它具有固定的宽高比例,并且可以缩放。如果我将其宽度和高度设置为 100%,它会尝试适应父级的大小,但它会保持宽高比例,因此如果它的比例不等于父级的比例,则在调整父级大小时,该组件附近可能会出现空白空间。
我需要的是使我的组件完全适合父组件的尺寸。有什么好的方法可以做到这一点吗?我可以监听父级的 resize
事件,并使用组件的 scaleX
和 scaleY
,但可能存在更好的方法来解决我的问题(任何财产?)。谢谢。
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个很好的方法是使用 greensock AutoFitArea。
编码很简单,如下所示,
它将限制内部的任何内容从那里开始执行给定的尺寸
(300,100)
,您只需更改区域
的宽度即可将为您解决一切问题。希望有帮助
A great way is to use greensock's AutoFitArea.
Coding is as simple as the following
which would constrain whatever is inside do the given dimensions
(300,100)
from there on out, you can just change thearea
's width and that will figure it all out for you.hope it helps
就我个人而言,我要做的是将父级中的组件设置为宽度/高度 100%,然后在组件本身中,覆盖 updateDisplayList 函数(返回未缩放的宽度/高度),然后调整您想要的任何子级的大小根据该容器的宽度/高度显示。像这样的事情:
应该这样做。
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:
Should do it.
组件应该保持其比例吗?如果没有,您可以像您所说的那样,侦听父级的调整大小事件并将宽度和高度设置为组件值。
如果组件应保持其比例,您可以调整组件背景的大小,使其适合父组件的大小,并分别调整组件内容的大小及其比例。
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.