类型 函数 库 widget.* 返回值 ProgressViewWidget 修订 版本 2024.3703 关键词 widget, progress, progressView, progressIndicator 另请参阅 ProgressViewWidget
创建一个 ProgressViewWidget 对象。
为了节省纹理内存,ProgressViewWidget 只能从 图像表单 创建。
ProgressViewWidget 对象不支持 缩放,也不支持通过 .width 或 .height 更改宽度/高度。
widget.newProgressView( options )
此函数接受一个参数 options
,它是一个包含以下参数的表:
字符串。分配给进度视图的可选标识。默认为 widget_progressView
。
数字。控件 x 和 y 中心点的坐标。如果定义了 left
和 top
值,则这些值将被覆盖。
数字。创建控件的左侧和顶部位置。如果指定,这些值将覆盖 x
和 y
参数。
数字。进度视图的总宽度。
布尔值。如果进度更改应为动画,则设置为 true
;如果进度更改应立即发生,则设置为 false
(或省略)。
数字。设置此值可水平偏移进度视图的填充区域。默认为 0
。
数字。设置此值可垂直偏移进度视图的填充区域。默认为 0
。
可以使用 图像表单 对进度视图控件进行视觉定制。如下例所示,可以使用 6 个帧来组装外部边框和内部填充条。外部边框由左帽(红色)、中间跨度(绿色)和右帽(黄色)组成。内部填充区域由左帽(橙色)、中间跨度(蓝色)和右帽(紫色)组成。
根据进度视图的宽度,外部边框帽保持图像表单中规定的尺寸,中间帧(绿色)拉伸以填充它们之间的宽度。当进度设置为高于 0.0
的任何值时,内部左帽和右帽将变为可见。然后,根据当前百分比,中间填充跨度(蓝色)将拉伸以填充两个帽之间的距离。
![]() |
→ | ![]() |
ImageSheet。进度视图的 图像表单 对象。
数字。外部边框左帽的帧索引。
数字。外部边框中间跨度的帧索引。
数字。外部边框右帽的帧索引。
数字。外部边框帧的宽度/高度。所有边框帧应共享相同的宽度和高度。
数字。内部填充左帽的帧索引。
数字。内部填充中间跨度的帧索引。
数字。内部填充右帽的帧索引。
数字。内部填充帧的宽度/高度。所有填充帧应共享相同的宽度和高度。
local widget = require( "widget" ) -- Create the widget local progressView = widget.newProgressView( { left = 50, top = 200, width = 220, isAnimated = true } ) -- Set the progress to 50% progressView:setProgress( 0.5 )
local widget = require( "widget" ) -- Image sheet options and declaration -- For testing, you can copy/save the image under "Visual Customization" above local options = { width = 64, height = 64, numFrames = 6, sheetContentWidth = 384, sheetContentHeight = 64 } local progressSheet = graphics.newImageSheet( "widget-progress-view.png", options ) -- Create the widget local progressView = widget.newProgressView( { sheet = progressSheet, fillOuterLeftFrame = 1, fillOuterMiddleFrame = 2, fillOuterRightFrame = 3, fillOuterWidth = 64, fillOuterHeight = 64, fillInnerLeftFrame = 4, fillInnerMiddleFrame = 5, fillInnerRightFrame = 6, fillWidth = 64, fillHeight = 64, left = 50, top = 200, width = 220, isAnimated = true } ) -- Set the progress to 50% progressView:setProgress( 0.5 )