问题
I'm using the code below for native Adroid scroller for Data Grid and it works almost OK. Almost, because in one particular view in my stack it seems to be unreliable. Download the stack and check the following: Go back and forth 3-4 times clicking between "My Categories" and "My Selection" then at some point the scrolling does not work in the "My Categories" view. I then have to restart the app and it works OK. What do you think it depends on? The code is:
on openCard
local tScrollerRect, tContentRect
// Only create a scroller on a mobile device
if environment() is not "mobile" then exit openCard
// Set the area of the scroller
put the rect of group "DataGrid 1" into tScrollerRect
// Set the area of the content to be scrolled
put 0,0,(the DGformattedWidth of group "DataGrid 1"),(the DGformattedHeight of group "DataGrid 1") into tContentRect
// Create the scroller control
mobileControlCreate "scroller", "loremScroll"
put the result into sScrollerID
// Set the properties of the scroller
mobileControlSet "loremScroll", "rect", tScrollerRect
mobileControlSet "loremScroll", "contentRect", tContentRect
mobileControlSet "loremScroll", "visible", true
mobileControlSet "loremScroll", "scrollingEnabled", true
mobileControlSet "loremScroll", "vIndicator", true
mobileControlSet "loremScroll", "vscroll", 0
end openCard
on closeCard
// Delete the scroller
if environment() is not "mobile" then exit closeCard
mobileControlDelete sScrollerID
end closeCard
on scrollerDidScroll hOffset, vOffset
// When the user scrolls move the displayed content
set the DGvScroll of group "DataGrid 1" to vOffset
end scrollerDidScroll
You can download the stack here.
回答1:
I downloaded and installed your stack. If I just scroll, all seems to work fine. If I click on My Categories, it doesn't scroll, probably because the contentRect is incorrect. If I click on My Selection, the datagrid is empty and obviously scrolling won't work.
I suggest you execute
put 0,0,(the DGformattedWidth of group "DataGrid 1"),(the DGformattedHeight of group "DataGrid 1") into tContentRect
mobileControlSet "loremScroll", "contentRect", tContentRect
every time when the script of one of the buttons All Categories, My Selection or My Categories runs.
来源:https://stackoverflow.com/questions/22943152/native-android-scroller-for-data-grid