ScrollView question

ziotullio

Member
Licensed User
Longtime User
Hello everybody, I know I am making an error but I am not able to fix it and need some help from you guys.

This is just some code to test the ScrollView capabilities:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   Dim ScrollView1 As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   ScrollView1.Initialize(800)
   Activity.AddView(ScrollView1,0,0,100%x,100%y)
   Dim pnl As Panel=ScrollView1.Panel
   pnl.Color=Colors.White 
   For i = 0 To 250
      Dim chk As CheckBox
      chk.Initialize("")
      chk.Text="Check #" & (i + 1)
      chk.TextColor=Colors.Blue
      pnl.AddView(chk,10dip,50dip * i + 50dip,150dip,50dip)
   Next   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Now the question is: Why the ScrollView just let me scroll only the first 14 CheckBoxes?

Thank you in advance for any hint and help.
:BangHead:
 

Kevin

Well-Known Member
Licensed User
Longtime User
Because you need to adjust the height of the panel in the scrollview after adding all of those views. See code below. I think my math/algebra is correct but if not, I'm sure you get the idea. :D

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    Dim ScrollView1 As ScrollView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ScrollView1.Initialize(800)
    Activity.AddView(ScrollView1,0,0,100%x,100%y)
    Dim pnl As Panel=ScrollView1.Panel
    pnl.Color=Colors.White
    Dim LastChkTop as Long ' NEW
    For i = 0 To 250
        Dim chk As CheckBox
        chk.Initialize("")
        chk.Text="Check #" & (i + 1)
        chk.TextColor=Colors.Blue
        LastChkTop = 50dip * i + 50dip  ' NEW
        pnl.AddView(chk,10dip,LastChkTop,150dip,50dip)  ' CHANGED
    Next

    pnl.Height = LastChkTop + 50dip ' Re-adjust panel height to top of last checkbox + its height  ' NEW
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Last edited:
Upvote 0

ziotullio

Member
Licensed User
Longtime User
:D
Many,many thanks guys for your quick help.
Your suggestions worked great!

All the best!

:sign0098::sign0098:
 
Upvote 0
Top