Android Question Label Height and top vertical spacing

fbritop

Active Member
Licensed User
Longtime User
Hi folks
I struggling with labels

I have the following function
B4X:
Sub getRect(b4xv As B4XView) As B4XRect
    Dim b4xc As B4XCanvas
    b4xc.Initialize(b4xv)
    Return b4xc.MeasureText(b4xv.Text, b4xv.font)
End Sub

If I execute:
B4X:
Dim cls As Label
cls.Initialize("")
cls.SingleLine=True
pInt.AddView(cls, 0,0,1dip,1dip)
b4xV=cls
b4xV.Font=xc.b4xFontBold(xc.bigSize*1.5)
b4xV.Text="Áap"
b4xV.Color=Colors.Yellow
Dim b4xr As B4XRect=xc.getRect(b4xV)
b4xV.SetLayoutAnimated(0, 0,0,b4xr.Width, b4xr.Height)
The outcome is
1720756353209.png


But if I execute:
B4X:
Dim cls As Label
cls.Initialize("")
cls.SingleLine=True
pInt.AddView(cls, 0,0,1dip,1dip)
b4xV=cls
b4xV.Font=xc.b4xFontBold(xc.bigSize*1.5)
b4xV.Text="a"
b4xV.Color=Colors.Yellow
Dim b4xr As B4XRect=getRect(b4xV)
b4xV.SetLayoutAnimated(0, 0,0,b4xr.Width, b4xr.Height)
1720756381701.png

The label pads verticaly as it was a string in an uppercase and with accent situation, althow it does not contain that characters

How can I achieve that the text anchors directly to 0x and 0y? with the width there is no problem. The thing comes out with the spacing from the label above the text

TIA (-->Shortcut to "Thanks In Advance")
 

fbritop

Active Member
Licensed User
Longtime User
Thanks @Erel

The problem is not that the height is not correct, is that there is this padding that I dont know why it forces, you can see the yellow spacing that the label has got on the top, or why if the measure is right, it does not seem to center the text correctly

1720792889081.png


I have attached a small project which shows the situation.
We cannot use the canvas.DrawText, becuse this labels need to be updated in text and color very frequently.
 

Attachments

  • Project.zip
    14.1 KB · Views: 18
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
We cannot use the canvas.DrawText, becuse this labels need to be updated in text and color very frequently.
And why ?

Attached, a project with a Panel and a B4XCanvas and the text refreshed.
A next step could be to make a CustomView.

1720864934358.png
1720864988853.png
 

Attachments

  • TESR_New.zip
    27.5 KB · Views: 23
Last edited:
Upvote 0
Top