iOS Question ScrollView Layout not scrolling

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I can't seem to get my layout to work correctly in a scrollview.

I have a layout called 'Layout1' this contains a bunch of objects in a panel. This panel is 610dip in height.

I have created another layout which has a ScrollView in it (ScrollView1). This layout is called 'ScrollViewLayoutOnly'.

I have loaded the 'ScrollViewLayoutOnly' layout and then tried to load the 'Layout1' in the scrollview like:
B4X:
Dim nc As NavigationController
    nc.Initialize("nc")
    NavControl = nc
    
    Page1.Initialize("Page1")
    
    Dim lp As Page
    lp.Initialize("lp")
    lp.RootPanel.Color = Colors.Red
    Dim rp As Page
    rp.Initialize("rp")
    rp.RootPanel.Color = Colors.Green
    smc.Initialize(Null, nc, Null)
    Main.app.KeyController = smc
    Page1.HideBackButton = True
    NavControl.SetNavigationBarVisibleAnimated(False)
    
    Page1.RootPanel.Color = Colors.Blue
    
    Page1.RootPanel.LoadLayout("ScrollViewLayoutOnly")    ' only has a ScrollView1
    ScrollView1.Panel.LoadLayout("Layout1")    ' has my layout with a panel which is 610dip in height
    
    ScrollView1.Left = 0dip
    ScrollView1.Width = 100%x
    ScrollView1.Height = 100%y - 50dip - 50dip
    ScrollView1.Top = 50dip
    ' I want it 50dip from the top of screen, and 50dip from the bottom of the screen
    
    ScrollView1.Panel.Height = 610dip
    ScrollView1.Panel.Width = 100%x
    
    nc.ShowPage(Page1)

The issue I have is it doesn't scroll, and the scrollview is at the top of the screen.
The layout isn't also 100% the width of the screen.

Anyone know where I have gone wrong ?
 

aaronk

Well-Known Member
Licensed User
Longtime User
Attached..

I had it in my main app, but just created the attached project for testing. (which is pretty much how I am doing it in my main app)

This seems to scroll, but still not showing the layout correctly.
 

Attachments

  • test.zip
    4.1 KB · Views: 206
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Make sure to go over this example: Multiple Pages Example

1. Why aren't you using anchors?
This code should be deleted:
B4X:
 ScrollView1.Left = 0dip
    ScrollView1.Width = 100%x
    ScrollView1.Height = 100%y - 50dip - 50dip
    ScrollView1.Top = 50dip
Instead set the anchors in ScrollViewLayoutOnly.

2. You should never assume that %x and %y are correct outside of the Resize event.

Relevant video tutorial:

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…