保持孩子固定大小
我有以下设置:
<mx:Canvas>
<mx:ViewStack width="800" height="600">
<mx:Canvas width="100%" height="100%">
<s:BorderContainer width="100%" height="100%">
<mx:Canvas x="80" y="46" width="640" height="480">
<custom:CustomComponent width="640" height="480" />
</mx:Canvas>
</s:BorderContainer>
</mx:Canvas>
</mx:ViewStack>
</mx:Canvas>
是我无法更改的。这是显示视频的东西。然而,由于某种原因,某些东西(我猜是一个容器)的大小为 800
x 600
。所以我在
内得到了滚动条。
有没有办法可以强制某个容器的所有子项不超过一定的宽度/高度。
I have the following setup:
<mx:Canvas>
<mx:ViewStack width="800" height="600">
<mx:Canvas width="100%" height="100%">
<s:BorderContainer width="100%" height="100%">
<mx:Canvas x="80" y="46" width="640" height="480">
<custom:CustomComponent width="640" height="480" />
</mx:Canvas>
</s:BorderContainer>
</mx:Canvas>
</mx:ViewStack>
</mx:Canvas>
The <custom:CustomComponent />
is something I can't change. It's something that displays videos. However, for some reason, something (a container I guess) gets the size 800
x 600
. So I get scrollbars inside the <custom:CustomCompnent />
.
Is there a way I can force all children of a certain container not to get beyond a certain width/heigth.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需重写自定义容器的 addChildAt() 方法即可。 (这也涵盖了 addChild() 方法,因为 addChild() 调用 addChildAt())。在那里,您可以检查宽度和高度,并添加changeWatchers以在组件的宽度/高度每次更改时进行检查。应该使用changewatchers,因为DisplayObject没有maxWidth/maxHeight属性(否则会更容易)。
编辑
当您想使用此代码时,只需创建一个扩展 Canvas 类的新类,如下所示:
为了然后使用简单的 mxml 添加此代码,您可以执行类似的操作。这将具有 Canvas 具有的所有功能,并使用您自己的 adchild() 功能进行扩展。
You could just override the addChildAt()-method of your custom container. (this also covers the addChild()-method, because addChild() calls for addChildAt()). There you can check the width and height and add changeWatchers to check every time the width/height of a component changes. the changewatchers should be used because DisplayObject does not have a maxWidth/maxHeight-property (else it would be even easier).
EDIT
When you want to use this code, just create a new class that extends the Canvas-class, like so:
In order to then add this using simple mxml, you can just do something like this. This will have all functionalities a Canvas would have, extended with your own adchild()-functionality.