B4A Library [B4X][XUI] ViewPos - source code

Discussion in 'Additional libraries, classes and official updates' started by LucaMs, May 9, 2018.

  1. LucaMs

    LucaMs Expert Licensed User

    A code module (also compiled as library), compatible with B4A, B4J and B4I, with few methods about views' position.

    As you know, in b4a we have:
    Code:
    SomeView.Left
    but we don't have:
    Code:
    SomeView.Right
    which is available in the Designer (script).

    Many times, surely you have written code like the following:
    Code:
    View1.Left = View2.Left + View2.Width - View1.Width
    and even more complicated code than this.

    With this "library" you can write:
    Code:
    ViewPos.SetRight(View1, ViewPos.GetRight(View2))
    which is simpler and also more readable, I think.





    FUNCTIONS:

    - GetBottom(Vw As B4XView) As Int
    Returns the bottom position of Vw.

    - GetRight(Vw As B4XView) As Int
    Returns the right position of Vw.

    - GetLocation(Vw As B4XView) As tLocation
    Returns the absolute position of Vw on screen.



    METHODS:

    - SetRight(Vw As B4XView, Right As Int)
    - SetRightAnim(Duration As Int, Vw As B4XView, Right As Int)
    Sets the right position of Vw.

    - SetBottom(Vw As B4XView, Bottom As Int)
    - SetBottomAnim(Duration As Int, Vw As B4XView, Bottom As Int)
    Sets the bottom position of Vw.

    - SetRelRight(ViewToMove As B4XView, RelativeView As B4XView, HorDistance As Int)
    - SetRelRightAnim(Duration As Int, ViewToMove As B4XView, RelativeView As B4XView, HorDistance As Int)
    Sets the right position of ViewToMove on left of RelativeView, spaced of HorDistance.

    - SetRelBottom(ViewToMove As B4XView, RelativeView As B4XView, VertDistance As Int)
    - SetRelBottomAnim(Duration As Int, ViewToMove As B4XView, RelativeView As B4XView, VertDistance As Int)
    Sets the bottom position of ViewToMove on top of RelativeView, spaced of VertDistance.

    - VerCenterBetween(ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView)
    - VerCenterBetweenAnim(Duration As Int, ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView)
    Centers vertically ViewToPlace between TopView and BottomView.

    - HorCenterBetween(ViewToPlace As B4XView, LeftView As B4XView, RightView As B4XView)
    - HorCenterBetweenAnim(Duration As Int, ViewToPlace As B4XView, LeftView As B4XView, RightView As B4XView)
    Centers horizontally ViewToPlace between LeftView and RightView.
     

    Attached Files:

    Last edited: Oct 10, 2018
  2. Claudio Oliveira

    Claudio Oliveira Active Member Licensed User

    Very useful indeed!
    Thanks for sharing. :)
     
    Levit and LucaMs like this.
  3. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    LucaMs likes this.
  4. LucaMs

    LucaMs Expert Licensed User

    The best... in generating errors :p
     
  5. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    Not Man...:D
     
    LucaMs likes this.
  6. LucaMs

    LucaMs Expert Licensed User

    upload_2018-10-10_5-19-33.png


    Dear @LucaMs,

    you did not need to write two copies of each method; the "xxxAnim" version would have been enough and in case you did not want the animation it was enough to set the duration to zero.

    Just:
    Code:
    VerCenterBetween(Duration As Int, ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView)
     
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