Flex 3:顶部对齐图像和标签
在 Adobe Flex 3 中,我有一个包含图像和标签的 HBox:
<mx:HBox width="240" verticalAlign="top" horizontalGap="8">
<mx:Image width="46" source="@Embed(source='/assets/blah.swf')"/>
<mx:Label text="Blah."/>
</mx:HBox>
我的目标是对齐图像的上边缘和标签的上边缘(即标签内大写字符的顶部)。 然而,无论我摆弄什么属性和样式,标签上方都会保留大约 6 个像素的恒定“填充”(用引号引起来,因为 paddingTop 为零),将其上边缘设置在图像的下方。 有谁知道为什么?
谢谢,西蒙
编辑:
paddingTop 没有解决问题。 我在这方面看到了相同的行为:
<mx:HBox width="240" verticalAlign="top" paddingTop="0">
<mx:Canvas width="46" height="46" backgroundColor="red" paddingTop="0"/>
<mx:Label text="Blah." paddingTop="0"/>
</mx:HBox>
我还验证了没有全局样式表干扰任何这些类。
编辑 2:
来自 mx.core.UITextField 源代码 (Flex 3.2.0),由 Label, ll 内部使用。 159:
<前><代码> /* TextField 的宽度和高度比 4 个像素大 文本宽度和文本高度。 */还有
public function getmeasuredHeight():Number { (...) 返回文本高度+TEXT_HEIGHT_PADDING; (...) }
我将标签的 paddingTop 设置为 -4,瞧,问题解决了! 但这并不是一个真正干净的解决方案......
In Adobe Flex 3, I have an HBox containing an Image and a Label:
<mx:HBox width="240" verticalAlign="top" horizontalGap="8">
<mx:Image width="46" source="@Embed(source='/assets/blah.swf')"/>
<mx:Label text="Blah."/>
</mx:HBox>
My Goal is to align the top edge of the Image and the top edge of the Label (the top of capital characters within the Label, that is). However, no matter what properties and styles I fiddle with, a constant "padding" (in quotes because paddingTop is zero) of some 6 pixels remains above the Label, setting its top edge below the Image's. Does anyone know why?
Thanks, Simon
edit:
paddingTop is not doing the trick. I'm seeing the same behaviour on this:
<mx:HBox width="240" verticalAlign="top" paddingTop="0">
<mx:Canvas width="46" height="46" backgroundColor="red" paddingTop="0"/>
<mx:Label text="Blah." paddingTop="0"/>
</mx:HBox>
I also verified that there's no global stylesheet interfering with any of those classes.
edit 2:
From the mx.core.UITextField source code (Flex 3.2.0) which is used internally by Label, ll. 159:
/* The width and height of the TextField are 4 pixels greater than the textWidth and textHeight. */
and also
public function get measuredHeight():Number { (...) return textHeight + TEXT_HEIGHT_PADDING; (...) }
Then I set my Label's paddingTop to -4, and voilà, problem solved! It's not really a clean solution, though...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚摆弄这个,似乎你必须实际将标签的 paddingTop 设置为零,因为如果你不声明任何填充,它将使用组件的内置填充,所以它不会零。
当我运行该示例时,这似乎有效。
编辑:很脏,但是已经修复了,对吧? ;)
I've just been fiddling around with this and it seems you have to actually set the paddingTop to zero for the Label, because if you don't declare any padding it will use the component's built-in padding, so it won't be zero.
This seemed to be working when I ran the example.
Edit: Dirty, but fixed, right? ;)