for p, d in pairs(data.abil or {}) do
local isShowAttr = true
if d.i == 0 and d.t == "[项链BUFF]:" then
buff1 = true
elseif d.i == 3 and d.t == '[鉴定属性]:' then
buff2 = true
end
if (n
这段代码没有根据容器大小调整长短的主要问题是:`lineSize.width` 直接使用了分割线的原始宽度,没有与容器宽度进行对比和调整。
根据浮生梦老师前端课程内容,需要获取容器宽度并与分割线宽度进行比较:
```lua
if p == 4 and buff1 and buff2 then
local linePanel = ItemTips.CreateIntervalPanel(list, _DefaultSpace, true)
if linePanel then
local lineSize = GUI:getContentSize(linePanel)
local containerWidth = GUI:getContentSize(list).width -- 获取容器宽度
-- 根据容器宽度调整分割线宽度
if lineSize.width > containerWidth then
GUI:setContentSize(linePanel, containerWidth, lineSize.height)
lineSize.width = containerWidth
end
listSize.height = listSize.height + lineSize.height + (_setVspace or 0)
listSize.width = math.max(listSize.width, lineSize.width)
end
end
```
或者使用更简洁的方式:
```lua
if p == 4 and buff1 and buff2 then
local linePanel = ItemTips.CreateIntervalPanel(list, _DefaultSpace, true)
if linePanel then
local containerWidth = GUI:getContentSize(list).width
GUI:setContentSize(linePanel, containerWidth, 2) -- 2是分割线高度
local lineSize = GUI:getContentSize(linePanel)
listSize.height = listSize.height + lineSize.height + (_setVspace or 0)
listSize.width = math.max(listSize.width, lineSize.width)
end
end
```
关键点:
1. 使用 `GUI:getContentSize(list)` 获取容器的实际宽度
2. 使用 `GUI:setContentSize(linePanel, width, height)` 调整分割线尺寸
3. 确保分割线宽度不超过容器宽度
这样就能根据容器大小自动调整分割线的长短了!