Ok guys I’ve finally worked out the problem/solution of this dilemma.
Here is sample code to show you what’s happening:
[lua]
local widget = require(“widget”);
local s = widget.newScrollView {
backgroundColor = { 0, 1, .3, .1 },
x = display.contentCenterX,
y = display.contentCenterY,
width = display.contentWidth,
height = display.contentHeight,
horizontalScrollDisabled = false,
verticalScrollDisabled = false
}
for i = 1, 100 do
local text = tostring(i) … " element in the scroll view"
local textLabel = display.newText(text, 0, (i+5) * 50, native.systemFont, 36);
textLabel.anchorX, textLabel.anchorY = 0,1;
s:insert(textLabel);
end
[/lua]
Here I create a regular scroll view, and insert 100 elements into the scroll view. However, I leave a buffer at the top of the scroll view, as can be seen in the following picture: http://imgur.com/me1CdNp,nN8BwsA,UCdCzz4#0
This buffer takes up approximately 5 elements of space.
When I scroll to the bottom, I should be able to see element 100; however, I can only see up to element 95.
http://imgur.com/me1CdNp,nN8BwsA,UCdCzz4#1
(To be clear, if you scroll past 95, you can still see 100, but if you let go of the scroll view, it bounces back to element 95. Run the code if you don’t know what I mean)
100 - 95 = 5 hidden elements
Buffer @ the top = 5 elements
Coincidence? I think not.
From this, I deduced that Corona set the scrollable height of the scroll view to the height of just the content in the scroll view. In my example, Corona set the scroll height to 100 elements (because there were 100 elements in the scroll view). However it failed to take into account the 5 element buffer at the top of the scroll view. Instead, it should have set the scroll height to 105 elements (to account for the extra buffer).
Is this what Corona is supposed to do? I think it would make more sense to include the height of the buffer into the recalculation of the scroll view’s scrollable height. If this is an error, I will report it (Btw, this error applies both top-down and left-right)
One quick solution for this dilemma is to add a ghost element to the top left corner of the scroll view. This way, Corona will not forget to factor in the height of the buffer zone:
[lua]
local widget = require(“widget”);
local s = widget.newScrollView {
backgroundColor = { 0, 1, .3, .1 },
x = display.contentCenterX,
y = display.contentCenterY,
width = display.contentWidth,
height = display.contentHeight,
horizontalScrollDisabled = false,
verticalScrollDisabled = false
}
–Ghost element
local topLabel = display.newText("", 0, 0, native.systemFont, 36);
s:insert(topLabel);
for i = 1, 100 do
local text = tostring(i) … " element in the scroll view"
local textLabel = display.newText(text, 0, (i+5) * 50, native.systemFont, 36);
textLabel.anchorX, textLabel.anchorY = 0,1;
s:insert(textLabel);
end
[/lua]
All fixed! Now you can see element 100 at the bottom of the scroll view:
http://imgur.com/me1CdNp,nN8BwsA,UCdCzz4#2
Of course, this isn’t too hard to do, but it is rather annoying, so I hope Corona fixes this bug(?) soon!