SL:print("==========加载传送员")
local list = {
{ name = "比奇城", mapId = "0" },
{ name = "盟重省", mapId = "3" },
{ name = "沙巴克城", mapId = "4" },
{ name = "白日门", mapId = "11" },
{ name = "苍月岛", mapId = "5" }
}
local n1_chuansong = {}
n1_c
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-06 17:48:24 |
👁️ 阅读: 1
这个警告信息是告诉你,你的滚动容器(ListView)内部内容高度小于等于容器本身的高度,引擎会自动强制调整尺寸。
问题出现在你的 `initButtons` 函数中。你每次点击按钮都调用 `GUI:removeAllChildren(list_v)` 清空列表,然后重新创建所有按钮,但你没有为 ListView 设置合适的高度和布局。
根据浮生梦老师前端课程内容,你需要为 ListView 设置合适的内置容器大小。参考聊天扩展的案例,应该这样修改:
```lua
-- 刷新界面
function n1_chuansong:initButtons()
-- 按钮容器初始化
local list_v = self.ui.ListView_1
if list_v then
GUI:ListView_removeAllChildren(list_v) -- 使用正确的函数清空
end
-- 计算需要的高度
local buttonHeight = 50 -- 假设每个按钮高度50
local totalHeight = #list * buttonHeight
-- 设置ListView的内置容器大小
GUI:ListView_setInnerContainerSize(list_v, 300, totalHeight) -- 300是宽度,根据实际情况调整
-- 创建容器内按钮
for k, v in ipairs(list) do
local bt = GUI:Button_Create(self.ui.ListView_1, "bt" .. k, 150, totalHeight - (k * buttonHeight) + buttonHeight/2, "res/custom/chuansong/an1.png")
GUI:Button_setTitleText(bt, v.name)
GUI:Button_setTitleFontSize(bt, 18)
GUI:Button_setTitleColor(bt, "#A0A0A4")
GUI:Button_setBrightStyle(bt, n1_chuansong.idx == k and 1 or 0)
GUI:Button_setTitleColor(bt, n1_chuansong.idx == k and "#FFFF00" or "#A0A0A4")
-- 添加按钮点击事件
GUI:addOnClickEvent(bt, function()
-- 更新选中索引
n1_chuansong.idx = k
-- 更新传送参数
n1_chuansong.p1 = k
-- 刷新所有按钮状态
self:initButtons()
end)
end
-- 执行布局
GUI:ListView_doLayout(list_v)
end
```
主要修改点:
1. 使用 `GUI:ListView_removeAllChildren` 而不是 `GUI:removeAllChildren`
2. 使用 `GUI:ListView_setInnerContainerSize` 设置内部容器大小
3. 使用 `GUI:ListView_doLayout` 执行布局
4. 正确计算按钮的Y坐标位置
这样设置后,ListView内部有足够的空间容纳所有按钮,就不会出现那个警告信息了。
← 返回问答库