B4J Question Designer Scripts!

Colin Evans

Active Member
Licensed User
Longtime User
Hi, getting myself in a mess trying to work with designer scripts
Basically, I have a Pane that's set to the width of the screen with left and right set to 10 in properties, and the height is set to 70,

What I am trying to do is put 9 labels in the panel that are 100% in height and spread evenly across the panel, I've tried a few this to set the width of each label to 11.11% of the panel but getting nowhere fast, to be honest, I'm not sure of the syntax even though I've tried various examples in B4A, is it different in B4J
 

josejad

Expert
Licensed User
Longtime User
Hi.

Maybe you can adapt this example?

 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Hi.

Maybe you can adapt this example?

Thanks, whilst it does go some way to solving my problem it doesn't spread the 9 labels evenly across the panel that is 100% of the width of the screen, so I'm back to playing with set width but given I now have nine labels across the panel the width of each label needs to be set to 11.11% and place according in the panel. If it's possible :(
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
If you want something like this, a small modification of @Erel 's example will do it.

panels.png


B4X:
'All variants script
n = 9: MaxSize = 50dip : MinGap = 5 'change here (n = number of views)
AllWidth = 100%x
w = Min((AllWidth + 22dip)/ n, MaxSize)
gap = (AllWidth - n * w) / n

'Only change the views names and 'i' value:
i = 0 : Label1.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 1 : Label2.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 2 : Label3.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 3 : Label4.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 4 : Label5.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 5 : Label6.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 6 : Label7.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 7 : Label8.SetLeftAndRight(i * gap + i * w,i * gap + (i + 1) * w)
i = 8 : Label9.SetLeftAndRight(i * gap + i * w, i * gap + (i + 1) * w)
Pane1.SetLeftAndRight(Pane1.Left, 10 + Label9.Right)
Pane1.SetLeftAndRight(50%x - Pane1.Width / 2, 50%x + Pane1.Width / 2)
 
Upvote 0
Top