Hello,
I was making an app for browsing names (humans) and I was stopped by an inaccurate result of numChildren for ScrollViewWidget. It always returns 3 even if the object doesn’t even have children or if children is more than 3. Is it a bug or am I doing something wrong?
Here’s my code:
local widget = require("widget") local backgroundPlayer = require("background") local objectSize = {x = 90,y = 90} local letters = {"A","B","C","D","E","F","G","I","H","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} local letterSelectionGroup = display.newGroup() local fontReallyBig = native.newFont("SinkinSans-200XLight.ttf",60) local fontBig = native.newFont("SinkinSans-300Light.ttf",35) local fontNormal = native.newFont("SinkinSans-300Light.ttf",20) local scrollViewGuideOptions = { x = 100, y = display.contentHeight/2, width = 300, height = display.contentHeight, horizontalScrollDisabled = true, friction = 0.7, scrollHeight = 3200, hideBackground = true } local scrollViewInteractiveOptions = { x = 100, y = display.contentHeight/2, width = 300, height = display.contentHeight, horizontalScrollDisabled = true, friction = 0.7, scrollHeight = 3200, hideBackground = true, isLocked = true } local scrollViewBackground = { x = 100, y = display.contentHeight/2, width = 300, height = display.contentHeight, fillColor = {1,1,1} } local mainScrollView = widget.newScrollView(scrollViewGuideOptions) local interactiveScroll = widget.newScrollView(scrollViewInteractiveOptions) local mSV\_Background = display.newRect(scrollViewGuideOptions.x,scrollViewGuideOptions.y,scrollViewGuideOptions.width,scrollViewGuideOptions.height) local rectBG = display.newRect(0,0,display.contentWidth,display.contentHeight) rectBG.anchorX = 0 rectBG.anchorY = 0 mSV\_Background:setFillColor(1,1,1,0.4) mSV\_Background.anchorX = 0 mainScrollView.anchorX = 0 mainScrollView:toFront() --local fontSmall = native.newFont("SinkinSans-200XLight.ttf",12) --local fontTiny = native.newFont("SinkinSans-200XLight.ttf",8) local letterIcons = {} backgroundPlayer:PlayBackground() rectBG:toBack() --mainScrollView for i = -2,#letters+2 do local options = { x = mainScrollView.width/2, y = 100+(150\*i), width = mainScrollView.width, height = 00, font = fontReallyBig, text = letters[i], fontSize = 80, align = "center" } local options2 = { x = mainScrollView.width/2, y = 100+(200\*i), width = mainScrollView.width, height = 200, } if letters[i] ~= nil then local newText = display.newText(options) mainScrollView:insert(newText) newText:setFillColor(0,0,0,0.8) else local newRect = display.newRect(options2.x,options2.y,options2.width,options2.height) newRect:setFillColor(1,0.8,0.8,0.4) mainScrollView:insert(newRect) end end mainScrollView:setScrollHeight(mainScrollView.numChildren\*200)--100+(200\*#letters)+300 -- Here print(mainScrollView.numChildren\*200) print(mainScrollView.numChildren)
I am unable to set the ScrollView’s scrollHeight correctly because of the wrong result.
Any help is welcome.