I'm using MainForm as a Splash screen in a FadeIn/FadeOut animation and at the end of it I'm trying to resize the form to the loaded layout size...
I have tried several approaches, but nothing seems to work...
Here's the sub that clears the rootpane from its previous contents and then loads the new layout...
B4X:
Sub FadeToLauncher_Tick
Log("Launcher")
FadeToLaunchTimer.Enabled = False
MainForm.RootPane.RemoveAllNodes
MainForm.RootPane.LoadLayout("Launcher")
MainForm.Initialize("Launcher", -1, -1) 'This SHOULD resize the form automatically, but it doesn't
End Sub
I know I can use a separate form to show my splash screen, but that is not my issue.
I just want to resize Mainform to the loaded layout!
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim t As Timer
Dim change As Boolean
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
change =True
MainForm.Show
MainForm.WindowWidth=400
MainForm.WindowHeight=400
t.Initialize("Timer",1000)
t.Enabled=True
End Sub
Sub timer_tick
If change Then
MainForm.WindowWidth=200
MainForm.WindowHeight=200
change = False
Else
MainForm.WindowWidth=600
MainForm.WindowHeight=600
change = True
End If
End Sub
which will work. I suppose, that
B4X:
MainForm.Initialize("Launcher", -1, -1)
only sets the inner width and height, but don't know
I have tried all the size related props, from the main form itself and from the inner rootpane... Nothing seems to work...
I have found out that it is related to a previously set of the form to maximized, and maybe also of the setting of the style to "TRANSPARENT" which cannot later be changed...I guess I will have to take a different approach...
as promised, this is the example of resizing the form to your layout. In this case I resize to the pane parent of the other nodes. (need javaObject)
B4X:
Sub ResizeFormToNodeBounds(FormTarget As Form, NodeTarget As JavaObject)
If Not(NodeTarget Is Node) Then Return
'Get the scene position:
Dim Scene As JavaObject
Scene = NodeTarget.RunMethod("getScene",Null)
FormTarget.WindowWidth = NodeTarget.RunMethod("getPrefWidth", Null) + Scene.RunMethod("getX", Null)
FormTarget.WindowHeight = NodeTarget.RunMethod("getPrefHeight", Null) + Scene.RunMethod("getY", Null)
End Sub
if you wonder why is the "scene" needed, it's to take into account the window's edge width.