iOS Question bt.CustomLabel.ALIGNMENT_LEFT does not work

Giusy

Active Member
Licensed User
Hi,
I create buttons programmatically but the instruction
bt.CustomLabel.TextAlignment = bt.CustomLabel.ALIGNMENT_LEFT
does not work, the alignement is always in center.
Also with ALIGNMENT_RIGHT the alignement is Center

which is the problem?

Thanks
 

Star-Dust

Expert
Licensed User
Longtime User
Show all the code, there will be some error or next code that restores the original state to the center.

(PS I told you there was something to cry about)
 
Upvote 0

Giusy

Active Member
Licensed User
:D :D.:D :p
I'm almost done, just a few tweaks
Here is the example zip
 

Attachments

  • scroll..zip
    2.9 KB · Views: 214
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm afraid that you cannot set the text alignment in a button.
The internal Label dimensions are adapted to the text size.
If you Log the Left and Width properties you get 0.
I made several tests, below the test code:
B4X:
    For y = 0 To rows-1
        Dim bt As Button
'        bt.Initialize("Button",bt.STYLE_SYSTEM)
'        bt.InitializeCustom("Button", Colors.RGB(0, 0, 128), Colors.Blue)
        bt.InitializeCustom("Button", Colors.White, Colors.Green)
        strlines =list1.get(y)
        bt.Text = strlines
        bt.Tag = y * columns
        bt.Color = Colors.Red
        bt.SetBorder(2dip, Colors.Blue, 10dip)
        bt.CustomLabel.Color = Colors.Blue
        bt.CustomLabel.Left = 0
'        Log(bt.CustomLabel.Left)
'        Log(bt.CustomLabel.Width)
        bt.CustomLabel.Width = bwidth
        bt.CustomLabel.AdjustFontSizeToFit = False
'        bt.CustomLabel.Font = Font.CreateNewBold(20)
        If y Mod 2 = 0 Then
            bt.CustomLabel.Font = Font.CreateNew(20)
        Else
            bt.CustomLabel.Font = Font.CreateNew(15)
        End If
        bt.CustomLabel.SetBorder(2dip, Colors.Yellow, 5dip)
        bt.CustomLabel.Multiline = False
        bt.CustomLabel.TextColor = Colors.RGB(0, 0, 128)
        bt.CustomLabel.TextAlignment = bt.CustomLabel.ALIGNMENT_LEFT
        screenscrollview.Panel.AddView(bt, 2dip, y * BHeight + 2dip, bwidth, BHeight-4dip)  'Add Button
    Next
There is maybe a possibility with NativeObject, but don't have enough experience.
 
Last edited:
Upvote 0

Giusy

Active Member
Licensed User
Hi @klaus
Thank you for the hard work you did, but always centered :(
It is incredible that such a simple instruction becomes so difficult
It' a bug!
 

Attachments

  • ALIGNEMENT.jpg
    ALIGNEMENT.jpg
    68.1 KB · Views: 206
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
After creating your button(s), add

B4X:
    Dim bno As NativeObject = myButton
    Dim myAlignment as int = 1       ' 0:Center    1:Left     2:Right
    bno.SetField("contentHorizontalAlignment", myAlignment)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I noticed that the values that are assigned to TextAlignment are different:
B4X:
 Lbl.TextAlignment=Lbl.ALIGNMENT_CENTER    ' 1: Center 0: Left 2: Right
So I thought about creating a small adaptation:
B4X:
Dim myAlignment As Int = (4 - Lbl.TextAlignment) Mod 3 ' 0:Center    1:Left     2:Right
 
Upvote 0
Top