VerticalCenter 未按预期工作?
我一直在尝试在 Flex 中的组内布置一些简单的形状,并且我似乎能够构建 VerticalCenter 无法完美居中事物的场景。如果运行下面的代码片段并将 HSlider 向左移动,您应该能够注意到菱形并不总是相对于矩形垂直居中。当菱形略大于矩形时,这一点尤其明显 - 在这种情况下,底部尖端伸出,而顶部尖端则不伸出。
我是否做了一些严重错误的事情,或者我只是违反了像素分辨率?或者还有什么?
希望有任何建议!
谢谢。
后编辑:添加另一个示例,甚至更简单,再次显示这一点。对我来说看起来像像素分辨率...
---- main.mxml ---
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<s:Group height="{hs.value}" width="80" verticalCenter="0" horizontalCenter="0">
<s:Rect height="100%" width="100%">
<s:fill>
<s:SolidColor color="0x787878"/>
</s:fill>
</s:Rect>
<local:diamond verticalCenter="0" height="100%"/>
</s:Group>
<s:HSlider maximum="40" value="30" id="hs"/>
</s:Application>
---- Diamond.mxml ------
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:Group height="100%" verticalCenter="0" scaleY="0.70">
<s:Path verticalCenter="0"
data="M 7.847 19.31
L 7.842 19.312
L 0 11.47
L 11.468 0
L 15.107 3.64
L 15.112 3.638
L 22.94 11.467
L 11.472 22.935
L 7.847 19.31 Z" >
<s:fill>
<s:LinearGradient rotation="90" scaleX="49.3475" x="11.47" y="-0.308">
<s:GradientEntry color="#FFD500" ratio="0"/>
<s:GradientEntry color="#F5A106" ratio="1"/>
</s:LinearGradient>
</s:fill>
</s:Path>
</s:Group>
</s:Group>
------------------ -------- 新示例 ----------------------
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="600" minHeight="400">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Group horizontalCenter="0" verticalCenter="0" width="80" height="40">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="0xdddddd"/>
</s:fill>
</s:Rect>
<s:Rect height="33" width="80" verticalCenter="0">
<s:fill>
<s:SolidColor color="0xFFFF99"/>
</s:fill>
</s:Rect>
</s:Group>
</s:Application>
内部矩形未在外部矩形中垂直居中。
I've been playing with laying out some simple shapes inside groups in Flex and I seem to be able to build scenarios where verticalCenter doesn't do a perfect job at centering things. If you run the snippet below and move the HSlider towards the left you should be able to notice that the diamond is not always vertically centered with respect to the Rect. This is particularly clear when you get to the diamond is slightly larger than the rect - in which case the bottom tip sticks out while the top one doesn't.
Am I doing something horribly wrong, or am I just hitting against pixel resolution? Or what else?
would love any advice!
thank you.
POST EDIT: adding another example, even simpler, that shows this again. Looks like pixel resolution to me...
---- main.mxml ---
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<s:Group height="{hs.value}" width="80" verticalCenter="0" horizontalCenter="0">
<s:Rect height="100%" width="100%">
<s:fill>
<s:SolidColor color="0x787878"/>
</s:fill>
</s:Rect>
<local:diamond verticalCenter="0" height="100%"/>
</s:Group>
<s:HSlider maximum="40" value="30" id="hs"/>
</s:Application>
---- diamond.mxml ------
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:Group height="100%" verticalCenter="0" scaleY="0.70">
<s:Path verticalCenter="0"
data="M 7.847 19.31
L 7.842 19.312
L 0 11.47
L 11.468 0
L 15.107 3.64
L 15.112 3.638
L 22.94 11.467
L 11.472 22.935
L 7.847 19.31 Z" >
<s:fill>
<s:LinearGradient rotation="90" scaleX="49.3475" x="11.47" y="-0.308">
<s:GradientEntry color="#FFD500" ratio="0"/>
<s:GradientEntry color="#F5A106" ratio="1"/>
</s:LinearGradient>
</s:fill>
</s:Path>
</s:Group>
</s:Group>
-------------------------- NEW EXAMPLE ----------------------
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="600" minHeight="400">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Group horizontalCenter="0" verticalCenter="0" width="80" height="40">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="0xdddddd"/>
</s:fill>
</s:Rect>
<s:Rect height="33" width="80" verticalCenter="0">
<s:fill>
<s:SolidColor color="0xFFFF99"/>
</s:fill>
</s:Rect>
</s:Group>
</s:Application>
the inner rectangle is not vertically centered in the outer one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在上一个示例中,您有一个 40 像素高的组,其中有一个 33 像素高的矩形,中间有 7 个像素,顶部和底部需要除以 2 (3.5)。
Flex 与 Flash 不同,对所有位置数字进行四舍五入,以获得更好的文本可读性和布局。如果您将内部矩形的高度更改为 32,它将完美居中。
本质上,不要使用小数位置。
In your last example, you have a 40 pixel high group that has a 33 pixel high rectangle within it, that makes 7 pixels in between that needs to be divided by 2 (3.5) for the top and bottom.
Flex, unlikes Flash, rounds all positional number for better text readability and laying out. If you were to change the inner rectangle height to 32, it would center perfectly.
Essentially, don't use fractional positions.
在此语句中,
您如何定义名称空间 testVerticalCenter?
In this statement
How are you defining the namespace testVerticalCenter?