Problem scrolling a scrollview to a position?

peve9

Member
Licensed User
Longtime User
Hi everyone!
We have tried this code to scroll a scrollview to a particular position, but we weren't able to do it:
B4X:
Expand Collapse Copy
Private Sub soft_HeightChanged (NewHeight As Int, OldHeight As Int)
   'Msgbox("NEW: " & NewHeight & CRLF & "OLD: " & OldHeight,"")
   Dim dif As Int
   dif = Abs(NewHeight-OldHeight)
   If NewHeight<OldHeight Then
   
   
      'sv.SetLayout(sv.Left,sv.Top,sv.Width,sv.Height-dif)
      'DoEvents
      sv.Height=sv.Height-dif
      sendButton.Top=sendButton.Top-dif
      edit.Top=edit.Top-dif
      'JumpToItem(GetSize)
      Msgbox(dif,"")
      DoEvents
      sv.ScrollPosition=sv.ScrollPosition+dif
      DoEvents
      Log("pippi")
      sv.Invalidate
   Else
      sv.Height=sv.Height+dif
      sendButton.Top=sendButton.Top+dif
      edit.Top=edit.Top+dif
   End If
End Sub

sv.scrollposition doesn't work... why? It seems that sv.scrollview hasn't been executed! WHY????????? :sign0085::sign0085:
 
The height is not the problem.. it works well.
The problem is the scrollposition

Place a msgbox outside of the If statement and see if that appears.
 
Upvote 0
As Klaus wrote you should first make sure that the position can actually be scrolled to.

You can try to use this reflection code:
B4X:
Expand Collapse Copy
Private Sub ScrollTo(pos As Int)
   'sv.ScrollTo smoothly scrolls to the position. In this case we want to immediately change the scroll position
   'so we use Reflection to call the native scrollTo method.
   Dim r As Reflector
   r.Target = sv
   r.RunMethod3("scrollTo", 0, "java.lang.int", pos, "java.lang.int")
End Sub
 
Upvote 0
Back
Top