Skip to content

EUIListLayout

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

  • Unit(4 属性 / 25 函数 / 6 事件)
    • EUINodeBase(34 属性 / 8 函数 / 4 事件)
      • [EUIListLayout](8 属性 / 1 函数)

继承成员

2 个来源 / 38 属性 / 33 函数 / 10 事件

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类型默认值说明
FillDirectionInt1 (Vertical)子节点的填充方向,决定排列主轴。
AutoLayoutBooltrue是否启用自动布局。当为 true 时,子节点的添加、移除或尺寸变化会自动触发重新布局。
PaddingVector2[0, 0]子元素之间的间距,以像素为单位。
HorizontalAlignmentInt0 (Left)子节点在水平方向上的对齐方式。
VerticalAlignmentInt0 (Top)子节点在垂直方向上的对齐方式。
SortOrderInt0 (LayoutOrder)子节点的排序依据。
WrapsBoolfalse是否允许子节点在容器边界处换行。
AutomaticSizeBoolfalse是否根据子节点内容自动调整容器自身尺寸。

关联类型

函数 (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()