`
darrenzhu
  • 浏览: 807019 次
  • 性别: 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.

                                                                                                                                                                                                                 
分享到:
评论

相关推荐

    Flex布局之关于组件的大小

    这是最基本的属性,用来设置或获取Flex组件的宽度。它可以直接赋值为一个具体的像素值、百分比或者其他单位。 #### 2. *maxWidth 和 *minWidth 这两个属性分别限制了Flex组件的最大和最小宽度。当组件的宽度受到...

    flex组件,功能强大的下拉框

    通过Flexbox,我们可以轻松地调整元素的大小、顺序和对齐方式,以适应不同的屏幕尺寸和方向。 2. **下拉框组件** 下拉框(Dropdown)是用户界面中常见的一种控件,用于显示一个可选列表。在Flex下拉框组件中,用户...

    flex组件

    它允许开发者在不同尺寸的设备上灵活地调整元素的大小和位置,尤其适用于响应式网页设计。在Web开发中,随着移动优先的设计理念普及,Flex布局已经成为现代网页布局的标准之一。 博文链接虽然没有提供具体内容,但...

    flex组件时间轴组件

    在本文中,我们将深入探讨“Flex组件时间轴”,这是一种在现代Web开发中广泛使用的界面元素。Flex组件时间轴主要用于组织和展示按照时间顺序排列的数据,它在各种项目中都有着重要的应用,尤其对于需要呈现时间序列...

    flex组件的所有源文件

    Flex组件是一种广泛应用于Web开发中的布局工具,尤其在创建响应式设计时,它能帮助开发者构建灵活、可自适应不同屏幕尺寸的用户界面。在Web前端开发领域,Flex布局(也称为Flexbox)已经成为现代CSS布局的标准,它...

    Flex 组件边框线样式

    Flex组件的边框线样式也需要根据不同的屏幕尺寸进行适配。可以使用Flex的布局管理器和媒体查询来实现不同分辨率下的样式切换。 7. 模式对话框(Modal Dialogs) 模式对话框通常需要有特殊的边框样式以突出其重要性...

    【完美翻译】Flex组件的生命周期

    Flex组件的生命周期是Adobe Flex框架中一个至关重要的概念,它涉及到UIComponent类及其子类(如Button、Canvas等)在创建、初始化、显示和销毁过程中的各个阶段。深入理解组件生命周期有助于开发者更有效地管理组件...

    flex 重写组件

    #### 一、为何需要重写Flex组件? 在Flex开发过程中,经常遇到已有的组件无法完全满足项目需求的情况。这些需求可能包括但不限于改变组件的外观、增加新的功能特性或者实现更复杂的交互逻辑。在这种背景下,重写...

    Flex中利用IFrame解决嵌入HTML时Flex组件被遮挡和IFrame被隐藏的问题

    解决这个问题的关键在于调整Z-index,即设置IFrame和Flex组件的层级关系。在Flex中,可以为每个组件设置`includeInLayout`属性和`zIndex`属性来控制它们在堆叠顺序中的位置。确保菜单组件的`zIndex`值高于IFrame,使...

    Flex 自定义组件ImageViewer

    组件生命周期是每个Flex组件从创建到销毁所经历的一系列阶段。理解组件生命周期至关重要,因为它涉及到组件何时初始化、何时准备显示、何时接收用户输入以及何时被销毁。以下是一些关键的生命周期方法: 1. **...

    flex组件(放大、缩小、拖动、最大化、最小化)

    1. **放大与缩小**:Flex组件可以通过JavaScript或CSS来实现大小调整。使用CSS,我们可以通过`resize`属性来允许用户手动调整元素大小,如`resizable: both;`。若需动态改变大小,可以结合JavaScript监听窗口大小...

    支持手动拖拽缩放flex组件的组件

    在给定的标题“支持手动拖拽缩放flex组件的组件”中,我们可以推断出这是一个专门针对Flex环境设计的组件,它允许用户通过手动拖拽和缩放操作来调整Flex应用中的组件大小。 描述中提到的“com.janisRadins.zip”很...

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

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

    flex 高级自定义组件

    而`updateDisplayList()`方法则用于在测量阶段之后,根据组件的尺寸和位置属性来定位和绘制子组件,包括它们的大小和位置。 布局方面的定制,主要涉及`measure()`和`layoutChrome()`方法。`measure()`负责计算组件...

    flex特效组件用法效果

    它特别适合用于现代网页和移动应用的设计,因为它可以自动调整元素的大小和位置以适应不同的屏幕尺寸。 首先,让我们理解Flex容器(ContainerCtrl)的概念。在Flex布局中,容器是包含一个或多个子元素的元素,这些...

    flex各组件对应样式

    在实际应用中,了解并熟练掌握这些Flex组件的CSS样式属性至关重要,这能帮助我们构建出高效、适应性强的前端界面。通过实践和不断试验,开发者能够更好地理解和运用这些属性,提升布局设计的灵活性和效率。

    深入FLEX组件生命周期

    ### 深入理解FLEX组件生命周期 #### 一、引言 在FLEX开发过程中,深入了解组件的生命周期对于优化应用程序性能、确保组件正确响应用户交互至关重要。本文将详细解析Flex组件生命周期的主要阶段:初始化...

    flex组件重写

    这通常发生在原生Flex组件无法满足我们的外观、行为或功能要求时。本文将探讨Flex组件重写的必要性、考虑因素、以及AS和MXML方式的选用规则,并提供AS方式重写组件的一般步骤。 一、为什么要重写组件 1. 扩展功能:...

Global site tag (gtag.js) - Google Analytics