Android Question Scrollview position till its end

adrianstanescu85

Active Member
Licensed User
Longtime User
Hello!

I have a scrollview that contains a panel and I'd like to programatically scroll this to its end. How do I do that? I tried setting the scrollposition to a certain value (somewhere at the bottom, i.e. close to the enclosed panel's height) but this wouldn't actually work. I even set the DoEvents after setting the scrollposition to a certain value, but nothing moved, it's still at the top.

Any ideas?

Thank you!
Adrian
 

skeat

New Member
Licensed User
Longtime User
Hi,

I am having a similar problem with ScrollView.ScrollPosition or ScrollView.ScrollToNow. I have to add the line DoEvents to make it scroll to position.

Something wrong with my code?

B4X:
Sub Process_Globals
    '
End Sub

Sub Globals
    Dim WholeScreen As Panel
    Dim scvText As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    WholeScreen.Initialize("")
    Activity.AddView(WholeScreen, 0, 0, 100%x, 100%y)
    WholeScreen.Color = Colors.White
    FillScrollView
End Sub

Sub Activity_Resume
    '
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    '
End Sub

Sub FillScrollView
    scvText.Initialize(100%y)
    WholeScreen.AddView(scvText, 2%x, 0, 96%x, 100%y)
    scvText.Color = Colors.Black

    Dim StrUtil As StringUtils
    Dim lblHeight, lblHeight1 As Float
   
    For i = 0 To 49
     Dim lbl As Label
     lbl.Initialize("evlbl")
     lbl.Color = Colors.White
     lbl.TextColor = Colors.Black
      lbl.Text = "This is line #" & (i+1)
     scvText.Panel.AddView(lbl, 0, lblHeight1, 96%x, 20dip)
     
     lblHeight = StrUtil.MeasureMultilineTextHeight(lbl, lbl.Text)
     lbl.Height = lblHeight + 12dip
     lbl.Gravity = Gravity.CENTER_VERTICAL

     lblHeight1 = lblHeight1 + lblHeight + 13dip
     scvText.Panel.Height = lblHeight1
    Next
   
    'DoEvents '<<<--- still needed to scroll to position???
    scvText.ScrollToNow(lblHeight1/2)
End Sub

Best Regards.
 
Upvote 0

skeat

New Member
Licensed User
Longtime User
Thanks Klaus for your quick response.

It's working if I just have DoEvents just before ScrollToNow.
B4X:
DoEvents 
scvText.ScrollToNow(lblHeight1/2)
Is it mandatory to have DoEvents before ScrollToNow?

Thanks.
 
Upvote 0
Top