Android的原生滚动不起作用

时间:2014-04-02 02:39:01

标签: android livecode

我正在尝试使用以下代码创建原生Android滚动条。我将堆栈保存为独立应用程序并安装到我的Android平板电脑,但文本不会滚动。

local sScrollerID

on preOpenCard
   local tScrollerRect, tContentRect

   // Only create a scroller on a mobile device
   if environment() is not "mobile" then exit preOpenCard

   // Set the area of the scroller
  put the rect of group "scrollArea" into tScrollerRect

   // Set the are of the content to be scrolled
   put the left of field "lorem",the top of field "lorem",the right of field "lorem",the formattedHeight of field "lorem" 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 preOpenCard

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 vScroll of group "scrollArea" to vOffset
end scrollerDidScroll

如何更正脚本?该堆栈适用于需要查看它的任何人:native scroll in android.zip

======

我还尝试为包含多个文本字段的组创建相同类型的滚动,即使有Mark的建议(见下文),它仍然不起作用。

代码在这里:

local sScrollerID

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 "scrollArea" into tScrollerRect

   // Set the area of the content to be scrolled
   put the left of group "scrollArea",the top of group "scrollArea",the formattedWidth of group "scrollArea",the formattedHeight of group "scrollArea" 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 vScroll of group "scrollArea" to vOffset
end scrollerDidScroll

我必须对群组滚动功能进行哪些更正? 可以从这里下载堆栈:native scroll in android-group.zip

=====

3)现在该组的滚动工作正常,我尝试使用此代码为数据网格创建相同的滚动:

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 formattedWidth of group "DataGrid 1"),(the formattedHeight 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 vScroll of group "DataGrid 1" to vOffset
 end scrollerDidScroll

但是数据网格的滚动不适用于此代码。我需要做些什么更正? 可以在此处下载堆栈:DG-android native scroller.zip

1 个答案:

答案 0 :(得分:0)

您正在获取某个字段的contectRect,然后尝试滚动一个组。您可能想要滚动字段,因此需要更改

on scrollerDidScroll hOffset, vOffset
   // When the user scrolls move the displayed content
   set the vScroll of group "scrollArea" to vOffset
end scrollerDidScroll

on scrollerDidScroll hOffset, vOffset
   // When the user scrolls move the displayed content
   set the vScroll of fld "lorem" to vOffset
end scrollerDidScroll

如果你真的想要滚动组,那么你需要在preOpenCard处理程序中将tContentRect设置为该组的formattedWidth和formattedHeight。