Layout_Create 容器怎么添加点击事件
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-12 16:03:43 |
👁️ 阅读: 24
Layout_Create创建的容器默认没有点击事件,需要先设置可点击属性,然后添加点击事件回调。
```lua
-- 创建容器
local container = GUI:Layout_Create(parent, "my_container", 100, 100, 200, 200, false)
-- 设置容器可点击
GUI:setTouchEnabled(container, true)
-- 添加点击事件
GUI:addOnClickEvent(container, function()
SL:print("容器被点击了!")
end)
```
注意:
1. `setTouchEnabled(container, true)` 必须设置为true才能响应点击
2. 如果容器内有子控件,可能需要设置`setSwallowTouches`来控制事件传递
3. 点击事件回调函数中可以使用`SL:print()`来调试
← 返回问答库