Android Question CENTER_HORIZONTAL at runtime

Tjitte Dijkstra

Licensed User
Longtime User
I know how to set CENTER_HORIZONTAL in the deisgner, but it must be possible at runtime?
I tried:


but it didn't work.
Who knows?

Tjitte Dijkstra

Licensed User
Longtime User

Thank you so far. I did not want to center the label as such, but the text within the label.
What I am doing is this: on a label (100%x in square) I place at runtime 100 smaller labels in which a number appears. But the numbers are aligned to the left and I want them centered. (Of course number 1 takes less place than 36 or 100, so it is nice to center all the numbers.)

Let me post a bit of code:
The is some Dutch in the code (tekst / blauw etc) but these are my variables.

Sub LabelCreator(Tekst As String) As Label
Dim t1,t2,t3 As String
L.Initialize("") 'L is in the Globals
If grijs = True Then L.TextColor=Colors.LightGray 'grijs = grijs
If blauw = True Then 'blauw = blue
If blauw = True Then L.Typeface=Typeface.DEFAULT_BOLD 'This works
If wit = True Then L.TextColor=Colors.white 'wit = white
t1 = Round2(UItslag/10,1)
If t1.length = 3 Then
t2 = t1.SubString2(0,1)'t2 becomes e.g. 2 if uitslag is 29
t3 = t1.Substring2(2,3)'t3 becomes e.g. 9 if uitslag is 29
t2 = t1-1 'the YYY coordinate
t3 = 10 'the XXX coordinate
End If
L.Text=Tekst 'The text (tekst in Dutch) for the tiny label
L.textstyle.HorizontalAlignment=HorizontalAlignment.CENTER_HORIZONTAL'This doesn't work and why?
Activity.AddView(L,(t3-1)*10%x+2.5%x,(t2)*10%x+3%x,6.5%x,5%x) 'The smal label, its position and size
End Sub
Upvote 0