主题
EUITableLayout
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUITableLayout](6 属性 / 1 函数)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
继承成员
2 个来源 / 38 属性 / 33 函数 / 10 事件
- 来自 EUINodeBase(34 属性 / 8 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release - 事件:
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、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUITableLayout 是 UI 表格布局容器,负责将子 UI 节点按行或列排列成网格。它支持设置主轴方向、间距、自动布局和自动扩容,并可通过 ApplyLayout 手动刷新布局。
适用场景
在制作背包、商店或设置界面时,需要将多个同类 UI 元素整齐排列成表格,此时可将 EUITableLayout 挂载到父节点下,由其统一管理子节点的位置和尺寸。
使用要点
通过 World:CreateUnit 创建 EUITableLayout 并挂载到当前玩家的 EUI 根节点,设置 MajorAxis、AutoLayout、Padding 等属性后调用 ApplyLayout 立即刷新布局。
注意事项
EUITableLayout 必须作为 EUI 节点的子级通过 World:CreateUnit 创建。AutoLayout=false 时,属性或子节点变化后需要显式调用 ApplyLayout;MajorAxis 使用 Enums.TableMajorAxis.RowMajor/ColumnMajor。不要调用 Meta 中 publish=false 的 Set 系列方法。
代码示例
创建表格布局并手动应用布局
lua
-- @runtime client
-- 获取当前玩家的 UI 根节点作为父容器
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
if localPlayer == nil then return end
local euiManager = localPlayer.PlayerGui.EuiManager
local rootNode = euiManager:GetRootNode()
-- 创建 EUITableLayout 实例,设置为主轴行优先、自动布局关闭
local tableLayout = game:GetService("World"):CreateUnit("EUITableLayout", {
Parent = rootNode,
Position = Vector2.New(100, 100),
Size = Vector2.New(300, 200),
MajorAxis = Enums.TableMajorAxis.RowMajor, -- 行优先排列
AutoLayout = false, -- 关闭自动布局,需要手动调用 ApplyLayout
FillEmptySpaceColumns = true, -- 列均分剩余空间
FillEmptySpaceRows = false,
Padding = Vector2.New(5, 5) -- 单元格间距 5 像素
})
-- 手动触发一次完整的布局计算和应用
tableLayout:ApplyLayout()
-- 输出布局信息以验证创建成功
print("表格布局已创建并应用,主轴模式:" .. tostring(tableLayout.MajorAxis))属性 (6)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
MajorAxis | Int | Enums.TableMajorAxis.RowMajor | 表格布局的主轴模式,决定子节点的排列方向。 |
AutoLayout | Bool | true | 是否自动进行表格布局。 |
FillEmptySpaceColumns | Bool | false | 是否让列均分剩余空间。 |
FillEmptySpaceRows | Bool | false | 是否让行均分剩余空间。 |
Padding | Vector2 | [0, 0] | 表格布局中每个单元格之间的间距,以像素为单位。 |
AutomaticSize | Bool | false | 是否根据子节点内容自动调整表格布局的尺寸。 |
关联类型
函数 (1)
ApplyLayout
签名:ApplyLayout() -> void
立即应用表格布局的当前设置,重新排列所有子节点。
返回值 void
示例代码
手动触发表格布局计算
lua
-- @runtime client
-- 获取当前玩家的 UI 根节点作为父容器
local players = game:GetService("Players")
local player = players.LocalPlayer
if player == nil then return end
local rootNode = player.PlayerGui.EuiManager:GetRootNode()
-- 创建 EUITableLayout 控件并设置基本属性
local tableLayout = game:GetService("World"):CreateUnit("EUITableLayout", {
Parent = rootNode,
Position = Vector2.New(100, 100),
Size = Vector2.New(300, 200),
MajorAxis = Enums.TableMajorAxis.RowMajor, -- 按行优先排列
AutoLayout = false -- 关闭自动布局,改为手动触发
})
-- 手动调用 ApplyLayout 立即执行一次布局计算
-- 当 AutoLayout 为 false 时,需要显式调用此方法才会重新排列子控件
tableLayout:ApplyLayout()
print("表格布局已手动应用")