`
darrenzhu
  • 浏览: 782383 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

设置Flex组件的尺寸大小

阅读更多

深红色部分标明了需注意的地方

另外要注意组件和容器的生命周期,确保你设置width和height是正确的时候,否则你设置了可能不发挥作用,可参考文章:http://help.adobe.com/en_US/flex/using/WS460ee381960520ad-2811830c121e9107ecb-7fff.html
http://livedocs.adobe.com/flex/3/html/help.html?content=ascomponents_advanced_2.html


参考文档:http://livedocs.adobe.com/flex/3/html/help.html?content=size_position_3.html

Determining and controlling component sizes
Flex determines the sizes of controls and containers based on the components and their properties and how you can use Flex properties to control the sizes.


Note: For a summary of the basic rules for component sizing, see Basic layout rules and considerations.

Basic sizing property rules
The following rules describe how you can use Flex sizing properties to specify the size of a component:

■Any dimension property that you set overrides the corresponding default value; for example, an explicitly set height property overrides any default height.
■Setting the width, height, maxWidth, maxHeight, minWidth, or minHeight property to a pixel value in MXML or ActionScript also sets the corresponding explicit property, such as explicitHeight or explicitMinHeight.
■The explicit height and width and the percentage-based height and width are mutually exclusive. Setting one value sets the other to NaN; for example, if you set height or explicitHeight to 50 and then set percentHeight to 33, the value of the explicitHeight property is NaN, not 50, and the height property returns a value that is determined by the percentHeight setting.
■If you set the height or width property to a percentage value in an MXML tag, you actually set the percentage-based value, that is, the percentHeight or percentWidth property, not the explicit value. In ActionScript, you cannot set the height or width property to a percentage value; instead, you must set the percentHeight or percentWidth property.
■When you get the height and width properties, the value is always the actual height or width of the control.

Determining component size
During the measurement pass, Flex determines the components' default (also called measured) sizes. During the layout pass, Flex determines the actual sizes of the components, based on the explicit or default sizes and any percentage-based size specifications.

The following list describes sizing rules and behaviors that apply to all components, including both controls and containers. For container-specific sizing rules, see Determining container size. For detailed information on percentage-based sizing, see Using percentage-based sizing.

■If you specify an explicit size for any component (that is not outside the component's minimum or maximum bounds), Flex always uses that size.
■If you specify a percentage-based size for any component, Flex determines the component's actual size as part of the parent container's sizing procedure, based on the parent's size, the component's requested percentage, and the container-specific sizing and layout rules.
■The default and percentage-based sizes are always at least as large as any minimum size specifications.
If you specify a component size by using a percentage value and do not specify an explicit or percentage-based size for its container, the component size is the default size. Flex ignores the percentage specification. (Otherwise, an infinite recursion might result.)
如果你只是给children设置了百分比值,但是对应的容器没有显示设置pixel值或百分比值,那么children使用的是其默认值,因为百分比值无法计算。

■If a child or set of children require more space than is available in the parent container, the parent clips the children at the parent's boundaries, and, by default, displays scroll bars on the container so users can scroll to the clipped content. Set the clipContent property to false to configure a parent to let the child extend past the parent's boundaries. Use the scrollPolicy property to control the display of the scroll bars.
■If you specify a percentage-based size for a component, Flex uses the viewable area of the container in determining the sizes.
■When sizing and positioning components, Flex does not distinguish between visible and invisible components. By default, an invisible component is sized and positioned as if it were visible. To prevent Flex from considering an invisible component when it sizes and positions other components, set the component's includeInLayout property to false. This property affects the layout of the children of all containers except Accordion, FormItem, or ViewStack. For more information, see Preventing layout of hidden controls.

Note: Setting a component's includeInLayout property to false does not prevent Flex from laying out or displaying the component; it only prevents Flex from considering the component when it lays out other components. As a result, the next component or components in the display list overlap the component. To prevent Flex from displaying the component, also set the visible property to false.

Determining container size
Flex uses the following basic rules, in addition to the basic component sizing rules, to determine the size of a container:

■Flex determines all components' default dimensions during the measurement pass, and uses these values when it calculates container size during the layout pass.
■If you specify an explicit size for a container, Flex always uses that size, as with any component.
■If you specify a percentage-based size for a container, Flex determines the container's actual size as part of the parent container's sizing procedure, as with any component.
■A percentage-based container size is advisory. Flex makes the container large enough to fit its children at their minimum sizes. For more information on percentage-based sizing, see Using percentage-based sizing.
If you do not specify an explicit or percentage-based size for a container, Flex determines the container size by using explicit sizes that you specify for any of its children, and the default sizes for all other children.
Flex does not consider any percentage-based settings of a container's children when sizing the container; instead, it uses the child's default size.
■If a container uses automatic scroll bars, Flex does not consider the size of the scroll bars when it determines the container's default size in its measurement pass. Thus, if a scroll bar is required, a default-sized container might be too small for proper appearance.
Each container has a set of rules that determines the container's default size. For information on default sizes of each control and container, see the specific container sections in the Adobe Flex Language Reference, and in Application Container; Using Layout Containers; and Using Navigator Containers.

深红色字体的部分需要特别注意,如果你没有给容器显示的设置pixel值或百分比的值,那么容器的宽度和高度是根据它的children的尺寸来计算的,如果某个child你显示的设置了值,就用该childe的显示值,否则就要child的默认值,而且在计算容器的尺寸时,是不考虑children的百分比设置值的,这些值对容器没有,只会用children的默认尺寸或显示的pixel值                                                                                                                                                                                                             

参考文档:http://livedocs.adobe.com/flex/3/html/help.html?content=size_position_2.html

About layout in Flex
The Layout Manager controls layout in Flex. The manager uses the following three-stage process to determine the size and position of each component in an application:

Stage 1 - Commitment pass
Determines the property settings of the application's components. This phase allows components whose contents depend on property settings to configure themselves before Flex determines their sizes and positions.



During the commitment pass, the Layout Manager causes each component to run its commitProperties() method, which determines the property values.

Stage 2 - Measurement pass
Calculates the default size of every component in the application. This pass starts from the most deeply nested components and works out toward the Application container. The measurement pass determines the measured, or default, size of each component. The default size of each container is based on the default or explicit (if specified) sizes of its children. For example, the Box container's default width is equal to the sum of the default or explicit widths of all of its children, plus the thickness of the borders, plus the padding, plus the gaps between the children.



During the measurement pass, the Layout Manager causes each component to run its measureSizes() method (a private method that calls the measure() method) to determine the component's default size.

Stage 3 - Layout pass
Lays out your application, including moving and resizing any components. This pass starts from the outermost container and works in toward the innermost component. The layout pass determines the actual size and placement of each component. It also does any programmatic drawing, such as calls to the lineTo() or drawRect() methods.



During the layout pass, Flex determines whether any component's sizing properties specify dimensions that are a percentage of the parent, and uses the setting to determine the child component's actual size. The Layout Manager causes each component to run its updateDisplayList() method to lay out the component's children; for this reason, this pass is also referred to as the update pass.

                                                                                                                                                                                                                 
分享到:
评论

相关推荐

    flex4舞台尺寸随浏览器窗口大小改变.rar

    flex4舞台尺寸随浏览器窗口大小改变.rar

    react-row:React 组件创建用于通过使用 flex 构建基于行和列(可选可调整大小)的复杂布局

    通过使用flex来创建基于行和列(可选可调整大小)构建复杂布局的 React 组件。 概述 这个想法很简单。 您将子组件添加到并且每个子组件都将附加到单独的列中。 每个充当容器,在其中自动计算其尺寸并更改 flex 值。 ...

    flex3的cookbook书籍完整版dpf(包含目录)

    使用Flex组件工具包创建组件 21.2节.在Flash中使用ContainerMovieClip创建Flex容器 21.3节.导入FlashCS3的组件 21.4节.认识Cairngorm小型结构 21.5节.创建Cairngorm视图、事件和模型 21.6节.创建Cairngorm命令和事务...

    kamamana:设计的欲望和激情。 样式指南,UI组件

    该库的主要目的是使用最新CSS属性(例如flex box等),而无需考虑支持旧的浏览器,不再使用浏览器前缀,从而使库(具有当前组件集)的大小保持较小。 我希望将其包括所有基本组件和依赖项的最大值保持在15Kb - 20...

    react-tree:React的分层对象树组件

    支持全高度或内容高度垂直大小调整(基于flex-box) 优化的UX可以清楚地指示打开/关闭的文件夹,所选项目以及对用户输入的React 针对长对象标签进行了优化:标签对于容器而言太大时省略号 针对深层嵌套结构进行了...

    wxPayShare

    加载机制封装组件启动项目毛线发球h5响应式方案个人电脑媒体查询flex,百分比初步布局移动端h5字体大小元素大小,布局元素边距,内填充rem + flex媒体查询+百分比+ flex 自由灵活rem布局方案视口物理上和页面上的...

    Altium Designer Beta 19.0.10完整版安装包+安装教程+和谐文件

    添加了在组件编辑器,资源管理器和ActiveBOM中为托管组件设置制造商零件选择排名的功能。 22653 将供应商部件号和制造商部件号的检索更改为批处理模式,以防止与BOM报告,SchLib编辑器和带有活动物料清单的OutJob中...

    软件界面设计工具_3款合集

    包含的Icon Express编辑程序支持16色、256色以及最大尺寸为127 x 127的真彩图标。 如果愿意同样能整合任意其它的图标编辑应用程序。 展示与原型 在可导航元素(如按键与窗口)之间创建连接以显示控制流程。 为...

    article-preview-component-master:文章页面,具有响应性显示和Javascript创建的功能

    根据组件的设备屏幕尺寸查看组件的最佳布局 单击共享图标时,查看社交媒体共享链接 需要挑战方面的支持吗? 并在#help频道中提问。 在哪里找到所有东西 您的任务是将项目扩展到/design文件夹中的/design 。 您会...

Global site tag (gtag.js) - Google Analytics