iOS Question ScrollView

Stefano Di Chiano

Active Member
Licensed User
Hi,
I'm having two problems with a scrollView in B4i.

The first is the background color. I'd like for it to be transparent, so that I can show the same background image when scrolling, but it's always white. Even setting the attribute to transparent in the designer doesn't change it. The scrollView shows some TextFields, Buttons and other views that I use as a user registration form.

The second is that it doesn't scroll through the whole panel that I loaded in it, but it stops more or less halfway.

The project is pretty big so I can't upload it but if you need more info I'll provide it. These are the code snippets with which I manage the scrollview:

B4X:
Public Sub Show
    If pg.IsInitialized = False Then
        pg.Initialize("pg")
        pg.RootPanel.LoadLayout("Scroll")
    End If
    Main.NavControl.ShowPage(pg)
    ScrollView1.Panel.LoadLayout("Register")
End Sub

B4X:
Private Sub pg_Resize(Width As Int, Height As Int)
    ScrollView1.ContentHeight = Panel1.Height
    ScrollView1.ContentWidth = Width
End Sub

How do I solve these two problems?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The scrollView shows some TextFields, Buttons and other views that I use as a user registration form.
Check B4XPreferenceDialog. Might save you a lot of time.
Also using xCLV will be simpler and cross platform.

It is strange that you need to change the ContentHeight when the page is resized.

Is the ScrollView anchored properly?

Make sure that the background color in Register layout is also transparent.
 
Upvote 0

Stefano Di Chiano

Active Member
Licensed User
It is strange that you need to change the ContentHeight when the page is resized.
Maybe this is my mistake.

Is the ScrollView anchored properly?
How should it be anchored? I set left for horizontal and top for vertical. Is that all right?

I noticed that if I set a higher ContentHeight though, instead of showing more content of the panel, it just show some of it but bigger.
I could try to make a smaller version of the project to upload if needed..
 
Last edited:
Upvote 0

Stefano Di Chiano

Active Member
Licensed User
Ok, I'll check that.
At this point though, I can't afford to change the whole project. Isn't there another way to fix this issue using a simple scrollView?
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
There are differences with Android, but in general ScrollView is able to work similar like under Android.
To set ScrollView height and width I use following subroutine
B4X:
Public Sub setScrollViewSize (scrollViewInstance As ScrollView, floatWidth As Float, floatHeight As Float, booleanBounces As Boolean)

         scrollViewInstance.Panel.Width   = floatWidth
        scrollViewInstance.Panel.Height  = floatHeight
        scrollViewInstance.ContentWidth  = scrollViewInstance.Panel.Width
        scrollViewInstance.ContentHeight = scrollViewInstance.Panel.Height

        scrollViewInstance.Bounces = booleanBounces
        scrollViewInstance.ScrollTo (0, 0, False)

End Sub

Bounces I typically set to False.
 
Upvote 0

Stefano Di Chiano

Active Member
Licensed User
To set ScrollView height and width I use following subroutine
It didn't solve my problem, but it made me understand where the problem could be:
basically the layout I'm loading in my scrollView has a panel with a height of 189%y. The scrollView shows only the content until 100%y of that panel and resize the items in it to fit scrollView.ContentHeight.
This is the layout:
layout.png

The scrollView only shows the items till the red line.

EDIT: I was finally able to find a solution by unchecking the "Handle resize event" flag. Now the whole panel is shown inside my scrollView.
 
Last edited:
Upvote 0
Top