Skip to content

EUIListView

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

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

继承成员

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

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类型默认值说明
BackgroundOpacityFloat1.0列表视图背景的不透明度。
BackgroundImageString""列表视图的背景图片资源标识。
ClippingEnabledBooltrue是否对列表内容进行裁剪。
BounceEnabledBooltrue是否启用列表的弹性滚动效果。
ItemsMarginInt0列表项之间的间距。
ScrollDirectionInt0列表的滚动方向。
ListviewGravityInt0 (Left)列表视图的对齐方式。
ScrollEnabledBooltrue是否允许列表滚动。

关联类型

函数 (2)

ScrollToPercent

签名:ScrollToPercent(percent: Float, time: Float, attenuated: Bool) -> void

将列表视图滚动到指定的百分比位置,并可以指定滚动动画的持续时间和是否使用衰减效果。

参数类型说明
percentFloat目标百分比(0~100)
timeFloat滚动时长(秒)
attenuatedBool是否衰减

返回值 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

将列表视图滚动到指定索引的项,并可以指定滚动动画的持续时间。

参数类型说明
itemIndexInt子项索引(从0开始)
timeFloat滚动时长(秒)

返回值 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)