Android Tutorial [B4X] [Visual Designer] Spreading Controls

Discussion in 'Tutorials & Examples' started by Erel, Sep 8, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    n = 4: MaxSize = 120dip : MinGap = 5dip 'change here (n = number of views)
    AllWidth = 100%x
    w = 
    Min(AllWidth / n - MinGap, MaxSize)
    gap = (AllWidth - n * w) / n

    'Only change the views names and 'i' value:
    i = 0 : Panel1.SetLeftAndRight((i + 0.5) * gap + i * w,(i + 0.5) * gap + (i + 1) * w)
    i = 
    1 : Panel2.SetLeftAndRight((i + 0.5) * gap + i * w,(i + 0.5) * gap + (i + 1) * w)
    i = 
    2 : Panel3.SetLeftAndRight((i + 0.5) * gap + i * w,(i + 0.5) * gap + (i + 1) * w)
    i = 
    3 : Panel4.SetLeftAndRight((i + 0.5) * gap + i * w,(i + 0.5) * gap + (i + 1) * w)
    Example is attached.

    [​IMG]

    [​IMG]
     

    Attached Files:

    • 1.zip
      File size:
      9.5 KB
      Views:
      75
    paragkini, kelevra1602, jmon and 16 others like this.
  2. hatzisn

    hatzisn Active Member Licensed User

    Great. Maybe in next update there could be a loop or auto code generation for this.

    Edit - Maybe this (loop) could be done with arrays of controls with reference to the array only in Designer
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice