主题
EUIListLayout
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUIListLayout](8 属性 / 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
- 属性:
EUIListLayout 是 UI 列表布局容器,用于自动排列子节点。它支持设置填充方向、间距、对齐方式和排序规则,并可通过 ApplyLayout 方法刷新布局。
适用场景
在 UI 列表中需要自动排列多个子控件时使用,例如背包物品列表或好友列表。
使用要点
通过 World:CreateUnit 创建实例,设置 Parent 为根节点,配置 FillDirection、Padding 等属性后调用 ApplyLayout 刷新布局。
注意事项
EUIListLayout 是 UI 列表布局容器,通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()(不能自行直接构造,也不能通过 GetService 获取 EUIManager)。设置布局属性后需调用 ApplyLayout 刷新子节点位置。
代码示例
创建列表布局并刷新子节点排列
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 listLayout = World:CreateUnit("EUIListLayout", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
local item = World:CreateUnit("EUIImage", {
Parent = listLayout,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
item.LayoutOrder = 1
item.Image = 'official://image/10066'
listLayout.FillDirection = 1
listLayout.Padding = Vector2.New(8, 8)
listLayout:ApplyLayout()属性 (8)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
FillDirection | Int | 1 (Vertical) | 子节点的填充方向,决定排列主轴。 |
AutoLayout | Bool | true | 是否启用自动布局。当为 true 时,子节点的添加、移除或尺寸变化会自动触发重新布局。 |
Padding | Vector2 | [0, 0] | 子元素之间的间距,以像素为单位。 |
HorizontalAlignment | Int | 0 (Left) | 子节点在水平方向上的对齐方式。 |
VerticalAlignment | Int | 0 (Top) | 子节点在垂直方向上的对齐方式。 |
SortOrder | Int | 0 (LayoutOrder) | 子节点的排序依据。 |
Wraps | Bool | false | 是否允许子节点在容器边界处换行。 |
AutomaticSize | Bool | false | 是否根据子节点内容自动调整容器自身尺寸。 |
关联类型
函数 (1)
ApplyLayout
签名:ApplyLayout() -> void
立即重新计算并应用当前布局设置,强制刷新子节点的位置与排列。
返回值 void
示例代码
刷新列表布局
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 listLayout = World:CreateUnit("EUIListLayout", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
listLayout.Padding = Vector2.New(8, 8)
listLayout:ApplyLayout()