I need to set the height of a scrollview so the layout that I have loaded into is scrolls. This is what I have done to load the layout;
B4X:
Scrollview1.Panel.LoadLayout("formlayout")
This works absolutely fine and the form is now within the scrollview. However, I need it to scroll so the remain parts can be accessed. There are 3 buttons that I cannot see. As a test I did the following;
B4X:
Scrollview1.Panel.Height=1000dip
But that did nothing. Is there something I'm missing?
I found what the issue was. I had declared and initialized the same ScrollView twice. Once in the Designer and again in code, which caused a conflict, that meant the command to resize was getting negated (or at least that's what appeared to be happening). Anyway, once I fixed this the resizing worked. However, having got passed this, I now have another question. Since I am loading a layout file into the Scrollview, is there anyway of determining using code what the height of the layout is so I can pass that to the Scrollview.Panel.Height method? At the moment I am getting the Bottom (Top+Height) value of the last Button view on the layout and passing that back. Quite happy to use this method as it works but, I always prefer to use system functions as they are far more reliable and take other factors into account, which I may not be aware of.
There is no 'system function' to get directly the needed height.
One solution is to put all your views onto a Panel and use use the height of this Panel for Scrollview.Panel.Height.
If the views in your layout are not on a Panel the method you used is the right and only one.
Excellent idea - Thank you! Would I be correct in thinking a Panel height can be extended beyond the physical device screen? A bit like having video buffer which sits outside of the video RAM range but, when scrolled becomes visible?
I took your advice and added all the controls into a panel using the Designer and then used the following to load it into a Scrollview.
B4X:
ScrollView0.Panel.AddView(Panel0,0,0,100%x,100%y)
However, this results in an error which is basic saying the view (panel) must be initialised. But surely if the panel I'm referrencing was created in the designer, there's no need to initilise it, right?
If you have defined the panel in the designer and set all the views in it as childs you must use: Scrollview1.Panel.LoadLayout("formlayout")
And set: Scrollview1.Panel.Height = Panel10.Height
You may have a look at this example: ScrollView example with a Panel higher than the screen
So instead of seeing the entire screen filled, I get only a fraction. See screenshot attached. I've also attached a screenshot of the Designer setup.
Surely it can't be as difficult as I'm making it. All I want to do is, in the parent panel (p) I want insert a scrollview that has all the form views that should be scrollable because the device screen will be variable when used the customers.
I see what I was doing wrong and it does make sense. However, having done what you suggested still didn't quite work but, no worries I abandoned the Scrollview and just stuck with the Panel. I think I need to spend a bit more time understanding Scrollviews and how to use them with other views.