主题
EUIListView
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUIListView](8 属性 / 2 函数)
- 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
- 属性:
EUIListView 是可滚动列表容器,用于在界面中展示大量子项并支持滑动浏览。它提供背景图片与透明度设置、裁切与回弹效果控制,以及通过百分比或索引滚动到指定位置的能力。
适用场景
常用于背包、商店、好友列表等需要展示动态数量条目的界面,通过将子节点加入列表容器并开启滚动与回弹,实现流畅的列表交互。
使用要点
通过 World:CreateUnit("EUIListView", { Parent = 根节点 }) 创建实例,设置 BackgroundImage 为 official://image/10000 等资源 URI,开启 ClippingEnabled 和 BounceEnabled,然后调用 ScrollToItem 或 ScrollToPercent 控制滚动位置。
注意事项
EUIListView 是可滚动列表容器,通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()。BackgroundImage 使用有效图片资源 URI,例如 official://image/10000;设置滚动、回弹和裁切后,将子节点加入列表容器。ScrollToPercent 的 percent 取 0~100;ScrollToItem 的 itemIndex 从 0 开始,且目标索引必须对应已有子项。
代码示例
创建列表视图并设置背景资源
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 listView = World:CreateUnit("EUIListView", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
listView.BackgroundImage = "official://image/10000"
listView.ScrollDirection = 1
listView.BounceEnabled = true
listView.ClippingEnabled = true
local item = World:CreateUnit("EUIImage", {
Parent = listView,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
})
item.Image = 'official://image/10066'属性 (8)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
BackgroundOpacity | Float | 1.0 | 列表视图背景的不透明度。 |
BackgroundImage | String | "" | 列表视图的背景图片资源标识。 |
ClippingEnabled | Bool | true | 是否对列表内容进行裁剪。 |
BounceEnabled | Bool | true | 是否启用列表的弹性滚动效果。 |
ItemsMargin | Int | 0 | 列表项之间的间距。 |
ScrollDirection | Int | 0 | 列表的滚动方向。 |
ListviewGravity | Int | 0 (Left) | 列表视图的对齐方式。 |
ScrollEnabled | Bool | true | 是否允许列表滚动。 |
关联类型
函数 (2)
ScrollToPercent
签名:ScrollToPercent(percent: Float, time: Float, attenuated: Bool) -> void
将列表视图滚动到指定的百分比位置,并可以指定滚动动画的持续时间和是否使用衰减效果。
| 参数 | 类型 | 说明 |
|---|---|---|
percent | Float | 目标百分比(0~100) |
time | Float | 滚动时长(秒) |
attenuated | Bool | 是否衰减 |
返回值 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 listView = World:CreateUnit("EUIListView", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(200, 300),
})
listView:ScrollToPercent(50, 0.3, true)ScrollToItem
签名:ScrollToItem(itemIndex: Int, time: Float) -> void
将列表视图滚动到指定索引的项,并可以指定滚动动画的持续时间。
| 参数 | 类型 | 说明 |
|---|---|---|
itemIndex | Int | 子项索引(从0开始) |
time | Float | 滚动时长(秒) |
返回值 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 listView = World:CreateUnit("EUIListView", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(200, 300),
})
World:CreateUnit("EUIImage", {
Parent = listView,
Size = Vector2.New(180, 48),
Image = "official://image/10066",
})
-- itemIndex 从 0 开始;0 表示第一个子项
listView:ScrollToItem(0, 0.5)