B4J Question Form layout problem

trueboss323

Active Member
Licensed User
Longtime User
I am getting started with B4J so pardon if it's a simple solution. I have a non-sizable form I declared 500 for both height and width in the project attributes. When I test it on a Windows computer with 2556 x 1440 resolution, the form and contents appears small , just how I want it. When I test it on a Mac with 1920x1080 resolution, the form is larger and its size makes it a bit unnecessary. So how can I can I change the form size/layout for the Mac without affecting the one for Windows ?
 
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
I am getting started with B4J so pardon if it's a simple solution.

I think we all were rockies at somepoint around here so dont worry for making "simple" questions.

There are 2 possible ways to do it:

2 layouts 1 form:
B4X:
    If fx.PrimaryScreen.MaxX = 1920 And fx.PrimaryScreen.MaxY = 1080 Then
        MainForm.RootPane.LoadLayout("layout1")
    Else
        MainForm.RootPane.LoadLayout("layout2")
    End If

1 layout to rule them all:

1.- Go to designer
2.- look for script_general (below the File menu)
3.- You can code here as if you were in main, it is a bit limited (of course it is only for design)
4.- There is no way (or at least i havent found it) to know screen size here, what i do is have a label with full horizontal/vertical anchor and adjust to it.
 
Upvote 0

trueboss323

Active Member
Licensed User
Longtime User
You don't need to create two layout files. You can create two variants in the same layout file.

However in most cases it is better to rely on anchors and designer script instead.

How do variants in B4J work compared to B4A ?
 
Upvote 0

trueboss323

Active Member
Licensed User
Longtime User
Same way as in B4A.

I am a bit confused because in B4A it was determined based on screen size. In B4J i don't know how the variant gets selected. If i put one variant with a width and height of 500, and add another one with 600 width/height, then which variant gets chosen? Hope that makes sense.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I think it's probably chosen based on form size, rather than screen size. Haven't tried it though.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yep, definitely on form size, just tried it.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Well I didn't expect it to change while the program was running, you learn something new every day :)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
test.gif


The above animation is from B4A Sdk Manager. The items from the list are created with a layout file with two variants. You can see how the version changes its position when the form becomes too narrow.
 
Upvote 0
Top