iOS Question General question about loadlayout

Filippo

Expert
Licensed User
Longtime User
Hi,

in my app I use 2 layout, one for horizontal alignment and one for vertical alignment. Via a menu option the user can select the alignment.
My question: under which sub should the layout be loaded, directly under pMain_Resize, pnlRoot_Resize, or somewhere else?
Is there any recommendation or it doesn't matter?

Currently it is loaded directly after Application_Start, but it doesn't seem to work quite right.

B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    pMain.Initialize("pMain")
    pMain.RootPanel.LoadLayout("Main")

    LoadApplayout 'Here is currently loaded
    ...
End Sub

Private Sub pMain_Resize(Width As Int, Height As Int)
    Dim r As Rect = pMain.SafeAreaInsets
    pnlRoot.SetLayoutAnimated(0, 1, r.Left, r.Top, Width - r.Right - r.Left, Height - r.Bottom - r.Top)
    'LoadApplayout 'Should it be loaded here?
End Sub

Private Sub pnlRoot_Resize(Width As Int, Height As Int)
    'LoadApplayout 'Should it be loaded here?
    ...
End Sub

Sub LoadApplayout
    If UserOrientation = Vertikal Then
        pnlRoot.LoadLayout("layVertikal")
    Else
        pnlRoot.LoadLayout("layOrizontal")
    End If
End Sub
 

Filippo

Expert
Licensed User
Longtime User
In most cases you should load the layout in Application_Start or B4XPage_Created.

Remember that the page can be resized many times. Anchors and designer script will be reapplied automatically (this is a different behavior than in B4A).
For apps where there is only one layout, everything is clear.
But in my example there are 2 different layouts, one vertical and one horizontal.
Please note that the switch via designer script, in this case, is not possible.
The question is, if the user changes the orientation via a menu option, where should the layout be loaded, under pMain_Resize, pnlRoot_Resize or somewhere else?
 
Upvote 0
Top