iOS Question When is layout ready for changes in code?

Martin Larsen

Active Member
Licensed User
I have this code in Application_Start:

B4X:
pnlBottomMain.LoadLayout("bottompanel")

pnlBottomMain.Height = pnlBottom.height-2
pnlBottomMain.Top = MainPanel.Height - pnlBottomMain.Height
However, the layout adjustments are not shown. But if I put the same two lines in a click handler, it works correctly.

This tells me that at the time the layout is loaded in the first line, it is not ready yet.

I have also tried to put the lines in page_resize but that doesn't work either.

Where or how should I make these small adjustments?
 

ilan

Expert
Licensed User
in application_start the height and weight of the Page are still not known.
you need to change the height weight after page_resize was called. (only if you really need to, it would make more sense to do that in the layout file)
 

Martin Larsen

Active Member
Licensed User
Watch the resize event video tutorial: https://www.b4x.com/etp.html
The more you can do in the layout files, the simpler things will be.
Thanks, I have seen the video already. I do most of the stuff in the layout designer script, but this I need to do in code. It is because another layout is loaded into a panel on the first layout so I can't address the panels in the script.

you need to change the height weight after page_resize was called.
Thanks. How do I know when page_resize was called?
 

Erel

Administrator
Staff member
Licensed User
Thanks. How do I know when page_resize was called?
It can be called many times.

It is because another layout is loaded into a panel on the first layout so I can't address the panels in the script.
I'm not sure that I understand but you can usually solve similar issues by splitting the layout into multiple layouts.
 

ilan

Expert
Licensed User
this is good if the resize happens only after the application was started. if you put this code in application_start you do get the correct behavior you want BUT resize event will also be called in other scenarios like Incoming call while the app is in the foreground.
now the question is will also Apllication_Start be called or only the resize event?
if only the resize event then you will need to think again when you need to set those lines. again it is hard to understand what he wants to archive.
 

Martin Larsen

Active Member
Licensed User
you can usually solve similar issues by splitting the layout into multiple layouts.
That is what I do. I have a main page and a page with a webview. They use the same bottom menu, so each of the two pages has a panel at the bottom. I then load another layout, called "bottompanel", into that panel.

But there is an issue with that. The bottom panel of the two pages has a height of 63. And the layout has the same height. Everything should be fine, but in fact the bottom panel of the two pages become higher than the layout height which looks bad. I have found this issue is caused by AutoScaleAll which for some reason resizes the panel and the layout differently. That is why I need to adjust the bottom panel height after the layout is finished loading. And doing it in application_start doesn't work as correctly stated in #3.

If I don't use AutoScaleAll it works as it should. But I like the way the fonts are scaled with AutoScaleAll.

Wait For B4XPage_Resize (Width As Int, Height As Int)
Looks promising, I will try that.

It's a B4X app btw, but I don't have the issue in Android.
 
Top