Any way to center a view?
-
23-02-2021 - |
Question
I noticed in the properties of the designer you can center the text in a label, etc. did not see anything that allows you to center the view itself.
For example, I looked at the properties for a button. There is Horizontal Alignment and Vertical Alignment for Text Style but I don't see anything like that for Button Properties.
Is there a way to control the button alignment?
Thanks.
Solution
You will need to do it programmatically:
Sub CenterView(v As View, parent As View)
v.Left = parent.Width / 2 - v.Width / 2
v.Top = parent.Height / 2 - v.Height / 2
End Sub
For example:
CenterView(button1, Activity)
OTHER TIPS
If you do have access to the .xml files ( I'm no basic4android expert ), you can look into the properies layout_gravity and gravity, depending on how you want to center.
Good luck!
/RandomSort
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow