Calculate textsize depending on label height

Spacewalker

Member
Licensed User
Longtime User
Hello,

I have some labels with varying heights.

I need a formular that can calculate a label.textsize that is always 50% of the height of the label (or 75%...)

So for example:
label height is 80 (in dip)
I need the value for .textsize that is half this height

If another label is 160 (dip) in height then I need .textsize double the size than in label.height=80

thx

Heinz
 

Woinowski

Active Member
Licensed User
Longtime User
Direct calculation

You can calculate it the following way:

Label1.textsize = Label1.height * 500/1000dip

or use any other number than 500.

Text sizes are always scaled to screen density, whereas values for view dimensions are in pixels.

Alternatively, coming from the textsize you can do this.

Label1.height = Label1.textsize * 2000dip/1000

Why the 1000? If you use one dip, you get strange rounding effect.

ACtually, reading your question exactly, you say you set label sizes with dips, so the second way is the correct one.
 
Upvote 0
Top