So, if i have a panel that is 428 tall, and i want to fit 5 labels in there that are 40 tall, How do I calculate and place them all evenly? Sometimes there might be 6 instead of 5 depending on the mode which is why i want to calculate this out.
Doing this dynamically in code btw, not in the visual designer.
Hey guys, This is my first time that I need a App supporting multiple screens.. and I'm a bit confuse, I can see on the forum the recommendation about to use "anchors", but also use dip.. then could you guys please let me know what is the best option for this situation: 7x3 buttons Each...
Question: How can I build a layout with X controls spread horizontally or vertically? Answer: You can use the designer script for this. As the designer script engine (currently) doesn't support loops it requires copying a few lines, however it is quite simple. The code goes like this: n = 4...
I dont want to use the designer script, Doing it in code because the thing will be dynamic. depending on whether you are running in basketball or volleyball mode, the number of entries change.
Something like this? I've not run it but the idea is fine.
B4X:
PanelHeight = 428
NumberOfLabels = 6
LabelHeight = 40
LabelTotalHeight = NumberOfLabels * LabelHeight
PanelFreeHeight = PanelHeight - LabelTotalHeight
VerticalGap = PanelFreeHeight / (NumberOfLabels + 1)
' there are now various ways of distributing the labels
Label1.Top = VerticalGap
Label2.Top = Label1.Bottom + VerticalGap
'...
' or in a loop you could use a Array, or a List with slightly different code
For i = 0 to labels.Length
Dim lbl As Label = Labels(i)
lbl.Top = (LabelHeight + VerticalGap ) * i + VerticalGap
Next
Something like this? I've not run it but the idea is fine.
B4X:
PanelHeight = 428
NumberOfLabels = 6
LabelHeight = 40
LabelTotalHeight = NumberOfLabels * LabelHeight
PanelFreeHeight = PanelHeight - LabelTotalHeight
VerticalGap = PanelFreeHeight / (NumberOfLabels + 1)
' there are now various ways of distributing the labels
Label1.Top = VerticalGap
Label2.Top = Label1.Bottom + VerticalGap
'...
' or in a loop you could use a Array, or a List with slightly different code
For i = 0 to labels.Length
Dim lbl As Label = Labels(i)
lbl.Top = (LabelHeight + VerticalGap ) * i + VerticalGap
Next
Thanks. I will play with it and see. Then I need to post a question on how to access all the UI objects that are using the label/pane parent for each one.
Ok, so i tried it and it didnt work. Here is the code:
B4X:
Dim PlayerSlots(6) As Pane
Dim StatPanelHeight As Int = 428
Dim NumberOfPanes As Int = 6
Dim PlayerSlotHeight As Int = 40
Dim PaneTotalHeight As Int = NumberOfPanes * PlayerSlotHeight
Dim PanelFreeHeight As Int = StatPanelHeight - PaneTotalHeight
Dim VerticalGap As Int = PanelFreeHeight / (NumberOfPanes + 1)
For I = 0 To 5 Step 1
PlayerSlots(I).Initialize("")
PlayerSlots(I).LoadLayout("PlayerSlot")
pnlHomeStats.AddNode(PlayerSlots(I), 0, (PlayerSlotHeight + VerticalGap) * 1 + VerticalGap, pnlHomeStats.Width, PlayerSlotHeight)
Next
Here is the result, only adding one layout into the one pane: