主题
EUIListLayout
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
- [EUIListLayout](8 属性 / 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
- 属性:
界面列表布局节点,用于把多个界面子节点按统一规则依次排列,支持设置填充方向、像素间距、水平与垂直对齐、排序依据、是否允许换行以及自动扩容。修改布局属性后需要显式刷新,才能让子节点位置按最新配置重新排列。
适用场景
适合用在需要成列或成行摆放一组界面元素的场合,例如把若干个条目节点挂到该布局节点下,再统一调整间距、对齐方式与换行策略,让列表随内容变化保持整齐。
使用要点
先取得当前玩家的根节点:localPlayer.PlayerGui.EuiManager:GetRootNode(),再调用 World:CreateUnit("EUIListLayout", { Parent = rootNode }) 创建布局实例并把需要排列的子节点挂在它下面。随后设置 FillDirection、Padding、HorizontalAlignment、VerticalAlignment、SortOrder、Wraps、AutomaticSize 等属性,最后调用 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 or localPlayer.PlayerGui == nil or localPlayer.PlayerGui.EuiManager == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
if rootNode == nil then return end
local listLayout = World:CreateUnit("EUIListLayout", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
if listLayout == nil then return end
local item = World:CreateUnit("EUIImage", {
Parent = listLayout,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
if item ~= nil then
item.LayoutOrder = 1
item.Image = 'official://image/10066'
end
listLayout.FillDirection = Enums.EUIFillDirection.Vertical
listLayout.Padding = Vector2.New(8, 8)
listLayout:ApplyLayout()
listLayout:Destroy()属性 (8)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
FillDirection | EUIFillDirection | Enums.EUIFillDirection.Vertical | FillDirection 是 EUIListLayout 的枚举属性(标题为“填充方向”),决定列表子项沿水平方向还是垂直方向排列。 |
AutoLayout | Bool | true | AutoLayout 是 EUIListLayout 的布尔属性(标题为“自动布局”),用于标记该列表是否启用自动布局。 |
Padding | Vector2 | [0, 0] | EUIListLayout 的 Padding 属性表示列表中相邻条目之间的间距,类型为 Vector2,其中 x 分量对应水平方向间距、y 分量对应垂直方向间距,单位按像素理解。默认值为 (0, 0),即条目不额外留白。 |
HorizontalAlignment | EUIHorizontalAlignment | Enums.EUIHorizontalAlignment.Left | HorizontalAlignment 是 EUIListLayout 的枚举属性(标题为“水平对齐”),控制列表内容在水平方向上的对齐方式。 |
VerticalAlignment | EUIVerticalAlignment | Enums.EUIVerticalAlignment.Top | VerticalAlignment 是 EUIListLayout 的枚举属性(标题为“垂直对齐”),控制列表内容在垂直方向上的对齐方式。 |
SortOrder | EUISortOrderType | Enums.EUISortOrderType.LayoutOrder | SortOrder 是 EUIListLayout 的枚举属性(标题为“排序依据”),用于指定列表子项的排序依据。 |
Wraps | Bool | false | Wraps 是 EUIListLayout 的布尔属性(标题为“允许换行”),用于标记列表在排列方向上是否允许换行排布。 |
AutomaticSize | Bool | false | AutomaticSize 是 EUIListLayout 的布尔属性(标题为“自动扩容”),用于标记列表是否按内容自动扩展尺寸。 |
关联类型
函数 (1)
ApplyLayout
签名:ApplyLayout() -> void
ApplyLayout 是 EUIListLayout 的布局刷新函数,调用后让该列表布局按照当前属性设置重新执行一次排布计算。
返回值 void
示例代码
刷新列表布局
lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil or localPlayer.PlayerGui == nil or localPlayer.PlayerGui.EuiManager == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
if rootNode == nil then return end
local listLayout = World:CreateUnit("EUIListLayout", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
if listLayout == nil then return end
listLayout.Padding = Vector2.New(8, 8)
listLayout:ApplyLayout()
listLayout:Destroy()