1卡上3-4个字段的原生android滚动条不起作用

时间:2014-05-17 01:12:17

标签: livecode

我想创建一个包含3-4个文本字段的卡片,每个字段都有一个原生的android滚动条。我按照这里的课程Creating a native scroller to scroll a field。我尝试将相同的代码用于另一张卡片,其中包含3个字段,这些字段组合在一起并进行编码,以便该组具有原生卷轴。通过该卡上的单独按钮可以使每个文本字段可见。打开应用程序时,滚动不起作用。 但是如果我去同一个堆叠上的另一张卡片,只需要空卡片,然后返回到主卡片,滚动就可以了。 所以卡片代码中有些内容我不知道理解并且必须修改,但是什么?

我在卡片中使用此代码:

    global gScrollField
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 gScrollField into tScrollerRect

   // Set the are of the content to be scrolled
   put 0,0,(the formattedWidth of gScrollField),(the formattedHeight of gScrollField) 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 gScrollField to vOffset
end scrollerDidScroll
 mouseControl

并在导航按钮中显示一个字段并隐藏代码所在的其他字段(例如卡片“b”:

    global gScrollField
on mouseUp
   put the long name of fld "b" into gScrollField
   hide fld "a"
   hide fld "c"
   show fld "b"
end mouseUp

指向堆栈的链接是: scroll 3-4 fields on the same card

1 个答案:

答案 0 :(得分:1)

问题在于,在按下a,b,c之一按钮之前,没有定义gScrollField:它最初导致preOpenCard处理程序失败。

我将卡片脚本修改为......

    global gScrollField
    local sScrollerID
    local sStarted

    on preOpenCard
       local tScrollerRect, tContentRect

       if sStarted <> true then
          put the long id of fld "a" into gScrollField
          hide fld "c"
          hide fld "b"
          show fld "a"
          put true into sStarted
       end if

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

它工作正常:) sStarted变量在第一次执行时初始化。