主题
EUITableLayout
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
- [EUITableLayout](6 属性 / 1 函数)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
继承成员
2 个来源 / 39 属性 / 36 函数 / 10 事件
- 来自 EUINodeBase(35 属性 / 12 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、TouchDragEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release、GetWorldPosition、ConvertToWorldPosition、ConvertToLocalPosition、HitTest - 事件:
OnTouchBegan、OnTouchMoved、OnTouchEnded、OnClicked
- 属性:
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUITableLayout 是 EUI 界面中的表格布局容器,用于把子节点按主轴方向组织成规整的行列结构。它通过 MajorAxis 决定以行还是以列为主轴,用 Padding 控制单元格间距,并可借助 FillEmptySpaceRows 与 FillEmptySpaceColumns 让行列均分剩余空间,AutomaticSize 则让容器随内容自动扩容。当需要手动控制刷新时机时,调用 ApplyLayout 重新计算并应用布局。
适用场景
适合在 EUI 界面里排布按钮、图标或信息卡片等规整网格,例如把一组功能入口按行或按列均匀摆放,并让容器尺寸随条目数量自动变化。
使用要点
通过 World:CreateUnit 创建 EUITableLayout 并挂载到当前玩家的 EUI 根节点,设置 MajorAxis、AutoLayout、Padding 等属性后调用 ApplyLayout 立即刷新布局。
注意事项
EUITableLayout 必须作为 EUI 节点的子级通过 World:CreateUnit 创建。AutoLayout=false 时,属性或子节点变化后需要显式调用 ApplyLayout;MajorAxis 使用 Enums.EUITableMajorAxis.RowMajor/ColumnMajor。
代码示例
创建表格布局并手动刷新布局
lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local layout = World:CreateUnit("EUITableLayout", {
Parent = rootNode,
Position = Vector2.New(10, 10),
Size = Vector2.New(200, 140),
MajorAxis = Enums.EUITableMajorAxis.RowMajor,
AutoLayout = false,
Padding = Vector2.New(4, 4),
})
if layout == nil then return end
layout:ApplyLayout()属性 (6)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
MajorAxis | EUITableMajorAxis | Enums.EUITableMajorAxis.RowMajor | EUITableMajorAxis 类型属性,属性标题为「主轴模式」,用于指定该表格布局排列子节点时的主轴方向。 |
AutoLayout | Bool | true | Bool 类型属性,属性标题为「自动布局」,用于控制该 EUITableLayout 是否启用自动布局能力。 |
FillEmptySpaceColumns | Bool | false | Bool 类型属性,属性标题为「列均分空间」,用于控制表格在列方向上的空余空间是否被均分填充。 |
FillEmptySpaceRows | Bool | false | Bool 类型属性,属性标题为「行均分空间」,用于控制表格在行方向上的空余空间是否被均分填充。 |
Padding | Vector2 | [0, 0] | EUITableLayout 的 Padding 属性用于设置表格布局中相邻单元格之间的间距,其类型为 Vector2,默认值为 (0, 0),即横向与纵向均不留空隙。该属性决定单元格排布时彼此保留的空白距离。 |
AutomaticSize | Bool | false | Bool 类型属性,属性标题为「自动扩容」,用于控制该表格布局是否根据内容自动扩展尺寸。 |
关联类型
函数 (1)
ApplyLayout
签名:ApplyLayout() -> void
EUITableLayout 的成员函数,用于触发该表格布局的一次布局计算与应用,把当前的排布属性(如主轴模式、间距、空白填充等)作用到布局下的子节点上。该函数不接收参数,也不返回结果。
返回值 void
示例代码
关闭自动布局后手动刷新
lua
-- @runtime client
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local layout = game:GetService("World"):CreateUnit("EUITableLayout", {
Parent = rootNode,
MajorAxis = Enums.EUITableMajorAxis.RowMajor,
AutoLayout = false,
})
if layout == nil then return end
layout:ApplyLayout()