Android Question Horizontal alignment of three (or more) panels

I have situation on layout where are three panels (with imageview) and I would like to align them horizontally. First panel would be on the left, last on the right and second will be in the middle. Is there some math or trick how to arrange them?
 

Attachments

  • Screenshot_20240226-141813.png
    Screenshot_20240226-141813.png
    38.7 KB · Views: 30
  • Screenshot_20240226-141813_1.png
    Screenshot_20240226-141813_1.png
    19.6 KB · Views: 30

emexes

Expert
Licensed User
Either in Layout Designer Script or in B4A code. Assuming panel sizes are already set (after loading layout) and you just want to align them horizontally with equal spacing, it'd be something like:

B4X:
Dim SpareSpace As Int = Panel1.Width - Panel2.Width - Panel3.Width - Panel4.Width    'big panel less three smaller panels
If SpareSpace < 0 Then Log("Houston, we have a problem")

Panel2.Left = 0
Panel3.Left = Panel2.Width + SpareSpace / 2
Panel4.Left = Panel1.Width - Panel4.Width
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
or "simpler" something like:
B4X:
Panel2.Left = 0    'obviously
Panel3.Left = (Panel2.Width + Panel1.Width - Panel4.Width - Panel3.Width) / 2    'center Panel3 at midpoint between inner edges of Panel2 & Panel4 šŸ™ƒ
Panel4.Left = Panel1.Width - Panel4.Width    'easy
 
Upvote 0
Top