iOS Question ScrollView Example

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Hi all,
I need a layout (like a web page) longer then phone screen.
I want scrool the page and i think i can use ScrollView.
But I neved used ScrollView....
I don't now if i have to use designer or not and how.
Can I have a simple example of ScrollView?
Thanks
Marcom
 

tufanv

Expert
Licensed User
Longtime User
Hi all,
I need a layout (like a web page) longer then phone screen.
I want scrool the page and i think i can use ScrollView.
But I neved used ScrollView....
I don't now if i have to use designer or not and how.
Can I have a simple example of ScrollView?
Thanks
Marcom
Hello,

First add your scrollview via designer and declare it. Later , lets say you will add 10 images to scrollview.
Use:
B4X:
ScrollView1.panel.AddView(img1,0,0,ScrollView1.Width,scrollview1.width)

This will add one square image to your scrollview . Later you can use the above code to add as more images as you like.
At the end ypu have to add :
B4X:
                    scrollmyfleet1.ContentHeight=all the content height
                    scrollmyfleet1.ContentWidth=scrollmyfleet1.width

(for example you added 10 images with height of 100 then it must be 1000, so it will scroll until height is 1000.
You must set the contentwidth to scrollview1.width so that it ill not scroll horizontally but it will only scroll vertically.
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Thanks Tufalv,
my scrollview in designel can be highter then screen?
I have to create a layout containig a scrollview that contains all my views or i must add views by code?
I haven't a list, but many views, so total hights are highter then screen hight.
Seee pic... I have other views to put in....
I can't resolve... have a sample
Thanks
 

Attachments

  • foto.PNG
    foto.PNG
    223.6 KB · Views: 202
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Thanks Tufalv,
my scrollview in designel can be highter then screen?
I have to create a layout containig a scrollview that contains all my views or i must add views by code?
I haven't a list, but many views, so total hights are highter then screen hight.
Seee pic... I have other views to put in....
I can't resolve... have a sample
Thanks

No, your scrollview in designer cant be higher than the screen. For example your screen height is 600 then your scrollview must be 600 at most BUT your scrollview's content height can be as much as you want. this way you can put may things in it and scroll down as much as you want.
As I know ypu cant add views to scrollpanel via designer , you have to add the views to scroll view with above code.

So seting ypur scrollview to screenheight and puting many views in it, and at the end, seting contentheight to height of all views in the scrollview will solve your problem.
 
Upvote 0

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Ok i understand, Thanks.
But I have a problem
I use this code:

B4X:
Public Sub Initialize
    hd.ProgressDialogShow("Attendere...")
    reqManager.Initialize(Me, Main.UrlDati)
   
    PageDett.Initialize("PageDett")
    PageDett.Title = ML.listaconv_title
    PageDett.RootPanel.LoadLayout("strutturascorre")
    Main.NavControl.ShowPage(PageDett)
  
    ScrView.Initialize("ScrView", 100%x, 500%y)
    ScrView.Color=Colors.Transparent
    PageDett.RootPanel.AddView(ScrView, 0, 0, 100%x, 100%y)

    Addaview

    ScrView.ContentHeight=500
    ScrView.ContentWidth=ScrView.width

End Sub

Sub Addaview
    strLBDenominazione.Initialize("strLBDenominazione")
    strIVrh.Initialize("strIVrh")
    strLBIndirizzo.Initialize("strLBIndirizzo")
   
    strLBDenominazione.height=30dip
    strLBDenominazione.width=100%x-strLBDenominazione.height-5dip
    strIVrh.height=strLBDenominazione.height
    strIVrh.width=strIVrh.height
    strLBDenominazione.Top=0%y
    strLBDenominazione.left=strIVrh.Left+strIVrh.Width+5dip
    strLBDenominazione.TextColor=Colors.RGB(0,0,255)
    strLBDenominazione.Font=Font.CreateNewBold(25)
    strLBIndirizzo.Top=strLBDenominazione.Top+strLBDenominazione.height
    strLBIndirizzo.left=5dip
    strLBIndirizzo.width=100%x-5dip
    strLBIndirizzo.height=strLBDenominazione.height
    strLBIndirizzo.TextColor=Colors.RGB(0,0,255)

    ScrView.panel.AddView(strIVrh,0,0,strIVrh.width,strIVrh.height)
    ScrView.panel.AddView(strLBDenominazione,strLBDenominazione.Left,strLBDenominazione.Top,strLBDenominazione.width,strLBDenominazione.height)
    ScrView.panel.AddView(strLBIndirizzo,strLBIndirizzo.Left,strLBIndirizzo.Top,strLBIndirizzo.width,strLBIndirizzo.height)

    strLBDenominazione.Text=denominazione
    strLBIndirizzo.Text=indirizzo
    strIVrh.Bitmap=Prh

End Sub

My layout "strutturascorre" contains only a scrollviev (named ScrView)
When i use this code first time i have only the empty screen
Then i push BACK
and then i recall my code
and i have correct screen (firste time, first screen. Second, third, forth.... time i have second screen)
What appens? Why?
thanks
Marcom

foto 3.PNG
foto 1.PNG
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Why do you initialize scrollview if you added it via designer ?

Ok i understand, Thanks.
But I have a problem
I use this code:

B4X:
Public Sub Initialize
    hd.ProgressDialogShow("Attendere...")
    reqManager.Initialize(Me, Main.UrlDati)
  
    PageDett.Initialize("PageDett")
    PageDett.Title = ML.listaconv_title
    PageDett.RootPanel.LoadLayout("strutturascorre")
    Main.NavControl.ShowPage(PageDett)
 
    ScrView.Initialize("ScrView", 100%x, 500%y)
    ScrView.Color=Colors.Transparent
    PageDett.RootPanel.AddView(ScrView, 0, 0, 100%x, 100%y)

    Addaview

    ScrView.ContentHeight=500
    ScrView.ContentWidth=ScrView.width

End Sub

Sub Addaview
    strLBDenominazione.Initialize("strLBDenominazione")
    strIVrh.Initialize("strIVrh")
    strLBIndirizzo.Initialize("strLBIndirizzo")
  
    strLBDenominazione.height=30dip
    strLBDenominazione.width=100%x-strLBDenominazione.height-5dip
    strIVrh.height=strLBDenominazione.height
    strIVrh.width=strIVrh.height
    strLBDenominazione.Top=0%y
    strLBDenominazione.left=strIVrh.Left+strIVrh.Width+5dip
    strLBDenominazione.TextColor=Colors.RGB(0,0,255)
    strLBDenominazione.Font=Font.CreateNewBold(25)
    strLBIndirizzo.Top=strLBDenominazione.Top+strLBDenominazione.height
    strLBIndirizzo.left=5dip
    strLBIndirizzo.width=100%x-5dip
    strLBIndirizzo.height=strLBDenominazione.height
    strLBIndirizzo.TextColor=Colors.RGB(0,0,255)

    ScrView.panel.AddView(strIVrh,0,0,strIVrh.width,strIVrh.height)
    ScrView.panel.AddView(strLBDenominazione,strLBDenominazione.Left,strLBDenominazione.Top,strLBDenominazione.width,strLBDenominazione.height)
    ScrView.panel.AddView(strLBIndirizzo,strLBIndirizzo.Left,strLBIndirizzo.Top,strLBIndirizzo.width,strLBIndirizzo.height)

    strLBDenominazione.Text=denominazione
    strLBIndirizzo.Text=indirizzo
    strIVrh.Bitmap=Prh

End Sub

My layout "strutturascorre" contains only a scrollviev (named ScrView)
When i use this code first time i have only the empty screen
Then i push BACK
and then i recall my code
and i have correct screen (firste time, first screen. Second, third, forth.... time i have second screen)
What appens? Why?
thanks
Marcom

View attachment 43612 View attachment 43613
 
Upvote 0
Top