techknight Well-Known Member Licensed User Longtime User Oct 9, 2018 #1 My math skills absolutely suck. Apparently. I am wracking my brain trying to figure out how to position a control in the center between two other controls. For example I have 4 labels. Two at the top of the screen next to each other, (height 50, height 120) one at the bottom of the screen. Layout: 1 2 <need 3 here> 4 How?
My math skills absolutely suck. Apparently. I am wracking my brain trying to figure out how to position a control in the center between two other controls. For example I have 4 labels. Two at the top of the screen next to each other, (height 50, height 120) one at the bottom of the screen. Layout: 1 2 <need 3 here> 4 How?
Jeffrey Cameron Well-Known Member Licensed User Longtime User Oct 9, 2018 #2 Are you doing this in designer script or in activity code? Upvote 0
techknight Well-Known Member Licensed User Longtime User Oct 9, 2018 #3 designer script. Trying to adapt to different screen sizes so the controls dont overlap. But I will need to do this programatically as well with some other controls Upvote 0
designer script. Trying to adapt to different screen sizes so the controls dont overlap. But I will need to do this programatically as well with some other controls
Jeffrey Cameron Well-Known Member Licensed User Longtime User Oct 9, 2018 #4 B4X: Label3.Top = Label2.Bottom + ((Label4.Top - Label2.Bottom) - Label3.Height) / 2 It makes a difference as the activity code lacks the ".Bottom" attribute. Upvote 0
B4X: Label3.Top = Label2.Bottom + ((Label4.Top - Label2.Bottom) - Label3.Height) / 2 It makes a difference as the activity code lacks the ".Bottom" attribute.
techknight Well-Known Member Licensed User Longtime User Oct 9, 2018 #5 That one worked. Wish my math skills were a bit better as I dont think I would have figured that one out. Upvote 0
That one worked. Wish my math skills were a bit better as I dont think I would have figured that one out.
Jeffrey Cameron Well-Known Member Licensed User Longtime User Oct 9, 2018 #6 techknight said: Wish my math skills were a bit better Click to expand... That's why I learned programming, so I could have the computer do the math for me That formula is the basic centering logic: B4X: Top/LeftPosition = (TotalSize - ObjectToCenterSize) / 2 Upvote 0
techknight said: Wish my math skills were a bit better Click to expand... That's why I learned programming, so I could have the computer do the math for me That formula is the basic centering logic: B4X: Top/LeftPosition = (TotalSize - ObjectToCenterSize) / 2
LucaMs Expert Licensed User Longtime User Oct 10, 2018 #7 https://www.b4x.com/android/forum/threads/b4x-xui-viewpos-source-code.92820/ - VerCenterBetween(ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView) Upvote 0
https://www.b4x.com/android/forum/threads/b4x-xui-viewpos-source-code.92820/ - VerCenterBetween(ViewToPlace As B4XView, TopView As B4XView, BottomView As B4XView)
Erel B4X founder Staff member Licensed User Longtime User Oct 10, 2018 #8 Might be slightly simpler to understand (designer script only): B4X: Label3.VerticalCenter = Label2.Bottom + (Label4.Top - Label2.Bottom) / 2 Last edited: Oct 10, 2018 Upvote 0
Might be slightly simpler to understand (designer script only): B4X: Label3.VerticalCenter = Label2.Bottom + (Label4.Top - Label2.Bottom) / 2