如何创建“垫片”在 Flex LinkBar 中?
我试图实现以下目标:创建一个宽度设置为100%的LinkBar,并将4个LinkButtons放在左侧,第5个按钮需要放置在右侧。起初,我试图将 2 个 LinkBar 控件放入 HBox 中,但是,这似乎破坏了 Flex 应用程序并导致黑屏。然后我尝试在链接栏的 dataProvider 属性中放置一个 mx:Spacer ,但它也不起作用,该间隔符仅跨越约 1 个字符宽,并且没有将第 5 个按钮一直推到右侧。请帮忙,谢谢。
I was trying to achieve the following: create a LinkBar with the width set to 100%, and put 4 LinkButtons on the left side, and the 5th button needs to be placed to the right side. At first, I was trying to put 2 LinkBar controls in a HBox, however, this seemed to corrupt the flex application and caused a blank screen. Then I tried to put a mx:Spacer in the dataProvider property of the linkbar, but it didn't work either, the spacer only spans about 1 character wide and didn't push the 5th button all the way to the right. Please help, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您需要对类进行猴子修补。 LinkBar 本质上是一个水平框,它自动在其子项之间添加间隔对象。查看 updateDisplayList 方法 - 请注意,分隔符的大小是使用这段代码设置的:
您需要以某种方式更改此行为。我的建议是检测这是否是对象中的最后一个间隔符(通过将循环迭代器“i”与子列表中的对象总数“n”进行比较),如果是,则将其宽度设置为 100%或同一事物的明确计算版本。
似乎对类进行猴子修补是实现此更改的最佳选择,因为任何尝试更改实际类之外(例如,在派生类中)的间隔大小的尝试都可能最终调用此方法并强制要重置的大小。
有关如何对课程进行猴子修补的详细信息,请观看Doug McCune 的简短演示 ,或查看 Jesse Warden 的这篇文章 他使用猴子补丁来更新 Flex 光标功能。
You're going to need to monkey-patch the class for this. LinkBar is essentially a horizontal box who automatically adds spacer objects between its children. Check out the updateDisplayList method - note that the size of the separators is set with this bit of code:
You'll need to change this behavior somehow. My recommendation is to detect if this is the last spacer in the object (by comparing the loop iterator "i" to the total number of objects "n" in the child list) and, if it is, set it's width to either 100% or an explicitly calculated version of the same thing.
It seems like monkey-patching the class is the best option to implement this change, as any attempt to change the size of the spacers outside of the actual class (in a derived class, for example) will probably wind up calling this method and forcing the size to reset.
For more information on how to monkey patch the class, watch this short presentation by Doug McCune, or check out this post by Jesse Warden where he uses a monkey patch to update the Flex cursor functionality.