Android Tutorial HOW YOU CAN USE ScrollView

hello
if you have a panel and you want scroll this panel then you use this source.

at first create scrollview in source code
then cut views in your panel and paste in scrollview panel
now show this


[CODE lang="b4x" title="code for default project" highlight="scroll view from panel"]' ______________________________________
If scvSetup.IsInitialized = False Then
scvSetup.Initialize(0)
Activity.AddView(scvSetup, 1%x, 0%y, 98%x, 100%y)
For Each myItem As View In pnlServer.GetAllViewsRecursive
Try
If myItem.As(View) <> Null Then
Dim Items As View = myItem.As(View)

myItem.As(View).RemoveView
scvSetup.panel.AddView(Items, Items.As(View).Left, Items.As(View).Top, Items.As(View).Width, Items.As(View).Height)
End If
Catch
Log(LastException)
End Try
Next
'scvSetup.Panel.Height = 1000dip'pnlSetup.Height
scvSetup.Panel.Height = 170%y'pnlSetup.Height
scvSetup.Panel.Width = 100%x'pnlSetup.Width
End If
scvSetup.ScrollPosition = 0
scvSetup.Visible = True
'_____________________________________________[/CODE]


and for b4xpages:

[CODE lang="b4x" title="for b4xpages projects" highlight="scroll"]' ______________________________________
If scvSetup.IsInitialized = False Then
scvSetup.Initialize(0)
root.AddView(scvSetup, 1%x, 0%y, 98%x, 100%y)
For Each myItem As View In pnlServer.GetAllViewsRecursive
Try
If myItem.As(View) <> Null Then
Dim Items As View = myItem.As(View)

myItem.As(View).RemoveView
scvSetup.panel.AddView(Items, Items.As(View).Left, Items.As(View).Top, Items.As(View).Width, Items.As(View).Height)
End If
Catch
Log(LastException)
End Try
Next
'scvSetup.Panel.Height = 1000dip'pnlSetup.Height
scvSetup.Panel.Height = 170%y'pnlSetup.Height
scvSetup.Panel.Width = 100%x'pnlSetup.Width
End If
scvSetup.ScrollPosition = 0
scvSetup.Visible = True
'_____________________________________________[/CODE]


use variable in global
[CODE lang="b4x" title="for b4xpages projects" highlight="scroll"]
Sub Globals
Private scvSetup As ScrollView
'These global variables will be redeclared each time the activity is created.
Private pnlServer As Panel
End Sub[/CODE]
 

Attachments

  • scroll.rar
    scroll.rar
    443.8 KB · Views: 669
  • Untitled.png
    Untitled.png
    16.8 KB · Views: 813
Last edited:
I don't quite understand this example.
You could, or rather should, simply load the layout into the ScrollView's internal panel.
B4X:
scvSetup.Panel.LoadLayout("...")

However, you don't need those "As(View)" nor the temporary Items variable.
B4X:
'  ______________________________________
    If scvSetup.IsInitialized = False Then
        scvSetup.Initialize(0)
        root.AddView(scvSetup, 1%x, 0%y, 98%x, 100%y)
        For Each myItem As View In pnlServer.GetAllViewsRecursive '<--- myItem already declared as View.
            Try ' <--- Don't use this in your code, except special cases (access to external sources), not in this one.
                If  myItem <> Null Then ' <--- could it be null?
                    myItem.RemoveView
                    scvSetup.panel.AddView(myItem, myItem.Left, myItem.Top, myItem.Width, myItem.Height)
                End If
            Catch
                Log(LastException)
            End Try
        Next
        'scvSetup.Panel.Height = 1000dip'pnlSetup.Height
        scvSetup.Panel.Height = 170%y'pnlSetup.Height
        scvSetup.Panel.Width = 100%x'pnlSetup.Width
    End If
    scvSetup.ScrollPosition = 0
    scvSetup.Visible =  True
 
Last edited:
I don't quite understand this example.
You could, or rather should, simply load the layout into the ScrollView's internal panel.
B4X:
scvSetup.Panel.LoadLayout("...")

However, you don't need those "As(View)" nor the temporary Items variable.
B4X:
'  ______________________________________
    If scvSetup.IsInitialized = False Then
        scvSetup.Initialize(0)
        root.AddView(scvSetup, 1%x, 0%y, 98%x, 100%y)
        For Each myItem As View In pnlServer.GetAllViewsRecursive '<--- myItem already declared as View.
            Try ' <--- Don't use this in your code, except special cases (access to external sources), not in this one.
                If  myItem <> Null Then ' <--- could it be null?
                    myItem.RemoveView
                    scvSetup.panel.AddView(myItem, myItem.Left, myItem.Top, myItem.Width, myItem.Height)
                End If
            Catch
                Log(LastException)
            End Try
        Next
        'scvSetup.Panel.Height = 1000dip'pnlSetup.Height
        scvSetup.Panel.Height = 170%y'pnlSetup.Height
        scvSetup.Panel.Width = 100%x'pnlSetup.Width
    End If
    scvSetup.ScrollPosition = 0
    scvSetup.Visible =  True
i test it

in some version not check is view or not

you must type AS(VIEW) for that version need know is view
 
Back
Top