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

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:
B4X:
SomeView.Left

but we don't have:
B4X:
SomeView.Right
which is available in the Designer (script).

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

With this "library" you can write:
B4X:
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.
 

Attachments

  • jxViewPos lib.zip
    3.8 KB · Views: 471
  • jxViewPos test.zip
    2.5 KB · Views: 445
  • ViewPos.bas
    5.5 KB · Views: 399
  • xViewPos lib.zip
    3.4 KB · Views: 453
  • xViewPos test.zip
    9.6 KB · Views: 458
Last edited:

LucaMs

Expert
Licensed User
Longtime 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.

- VerCenterBetween(ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView)
- VerCenterBetweenAnim(Duration As Int, ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView)
Just:
B4X:
VerCenterBetween(Duration As Int, ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView)
 
Top