问题
I'd like to use Android native scroller for a Data Grid displaying about 700 records. The scroller code below is in the card that has the Data Grid on it. The card script is:
on openCard
dispatch "ResetList" to group "DataGrid 1"
if text of fld "view" of cd "main" is "Favourites" then
send "mouseUp" to btn "favourites" of cd "home"
end if
RefreshAllLines
local sScrollerID,isScrolling
## Create scroller now:
create_scroller
end openCard
on closecard
delete_scroller
end closecard
command create_scroller
put "DataGrid 1" into tScrollerGroup
if the environment <> "mobile" then
exit create_scroller
end if
## Create native scroller object and save its ID in a local variable
MobileControlCreate "scroller"
put the result into sScrollerId
## RECT is the area on the card where the SCOLLER should do its work
MobileControlSet sScrollerId, "rect", (the rect of grp tScrollerGroup)
put the width of grp tScrollerGroup into tWidth
put the dgFormattedheight of grp tScrollerGroup into tHeight
set the dgvScroll of grp tScrollerGroup to 0
## WHAT part fo the datagrid shall be scrolled-> the complete datagrid
MobileControlSet sScrollerId, "contentRect", (0,0,tWidth,tHeight)
## Display SCROLLER
MobileControlSet sScrollerId, "visible", "true"
## the typical BUMP effect when you ge to the edge of the object
MobileControlSet sScrollerId, "canBounce", "true"
MobileControlSet sScrollerId, "pagingEnabled", "false"
MobileControlSet sScrollerId, "vIndicator", "false"
MobileControlSet sScrollerId, "borderStyle", "none"
MobileControlSet sScrollerId, "canScrollToTop", "false"
end create_scroller
## Will be sent when the user actually SCROLLs with his finger
on scrollerDidScroll OffsetX, OffsetY
lock screen
put true into isScrolling
set the dgvScroll of grp "DataGrid 1" to OffsetY
unlock screen
end scrollerDidScroll
## REMOVE native object when card closes!
command delete_scroller
if the environment <> "mobile" then
exit delete_scroller
end if
MobileControlDelete sScrollerId
end delete_scroller
--local isScrolling
on mouseUp
if not isScrolling then
send mouseUp to field "Label" of group "Row Template 0003" \
of group "dgList" of group "dgListMask" of group "DataGrid 1" of card "main"
end if
end mouseUp
on mouseDown
put false into isScrolling
end mouseDown
The code works very well when used for a text field but when used for the Data Grid the scrolling is slow and sluggish.
Is it due to a code or the innate functioning of the data Grid?
How to improve the responsiveness and the speed of the scrolling?
The link for my stack is: DG-only-1.16.zip To test the Data Grid srolling in the standalone click on "Select All", then "Lines" and then "Entire Selection"
I added 2 buttons on the card with the data grid for testing purposes. The upper one is switching the layerMode of the DG to scrolling/static and the lower one is switching the acceleratedRendering of the stack On/Off.
Surprisingly, I've noticed that the scrolling is slightly better with acceleratedRendering turned Off and the layerMode of the DG set to scrolling and slightly more sluggish with acceleratedRendering turned ON! The link for the new stack with added buttons is: DG-only-1.16+accelRend.zip
buttons codes:
on mouseUp
## Switch layerMode
if the label of me is "Off" then
set the label of me to "On"
set the layerMode of group "DataGrid 1" to "scrolling"
else
set the label of me to "Off"
set the layerMode of group "DataGrid 1" to "static"
end if
end mouseUp
and
on mouseUp
## Switch acceleratedRendering on and off
if the label of me is "Off" then
set the label of me to "On"
set the acceleratedRendering of this stack to true
else
set the label of me to "Off"
set the acceleratedRendering of this stack to false
end if
end mouseUp
回答1:
I don't do any Android development so I can't test. One thing that sticks out is the lock screen in scrollerDidScroll. I've seen lock screen calls called very frequently slow things down before. Can you try removing the lock screen call in scrollerDidScroll and letting me know if that improves performance at all?
You might also try changing the data grid group layerMode to "scrolling".
Let me know if either of those improves performance.
来源:https://stackoverflow.com/questions/24627756/how-to-increase-the-speed-of-the-native-android-scroller-for-the-data-grid