Help with automatic centering of text

rfresh

Well-Known Member
Licensed User
Longtime User
I know this should be an easy thing to figure out, but my code to auto-center label text isn't working the way I want.

I have 3 labels of varying text length. What I expected to see on the screen was something like this (I'm using underscore on this post as spaces otherwise spaces are removed):

_____This is label text line one
___This is label text line one two
This is label text line one two three

But what I got was this:
This is label text line one
This is label text line one two
This is label text line one two three

My code:
B4X:
bl_Title.Left = (pScreenWidth - lbl_Title.Width) / 2

But clearly this is not right?

Thanks...
 

Ricky D

Well-Known Member
Licensed User
Longtime User
try this

B4X:
Dim l As Label
l.Gravity = Gravity.CENTER_HORIZONTAL

it's as simple as that!

regards, Ricky
 
Upvote 0
Top