What unit is TextSize?

Mike Henry

Member
Licensed User
Longtime User
What unit is TextSize and ItemHeight (LineSpacing) in?
They don't seem to work together in a ListView when the screen resizes.
And what unit is used for object placement if dp is not specified?
 

klaus

Expert
Licensed User
Longtime User
TextSize is a Float, floating point variable.
The unit is a typography point.
TextSize is density independant !

ItemHeight is an Int, integer variable.
The unit is a pixel.
To get the same physical dimension (almost) you should always use dip values.
dip is for density independant pixel.

@thedesolatesoul
To make them the same size:
x.TextSize = 20
x.ItemHeight = 20dip
This is not the same.
A TextSize of 20 will not fit into a 20dip heigh view !

Best regards.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
TextSize is a Float, floating point variable.
The unit is a typography point.
TextSize is density independant !

ItemHeight is an Int, integer variable.
The unit is a pixel.
To get the same physical dimension (almost) you should always use dip values.
dip is for density independant pixel.

@thedesolatesoulThis is not the same.
A TextSize of 20 will not fit into a 20dip heigh view !

Best regards.
I see. Thank you Klaus, I never knew this.
I shall remove my wrong answer.
 
Upvote 0

Mike Henry

Member
Licensed User
Longtime User
Thanks for the info. That is pretty much what I thought,
but when I use:
TextSize = 20
ItemHeight = 30
the text will fit at 120 dpi but gets clipped at 160 dpi
regardless of whether ItemHeight is dip or not.
Looks like I'll have to experiment with that some more.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm not estonished.
As I told you, for pixel values you should use dip values.
So you must use:
B4X:
ItemHeight = 40dip
ItemHeight = 30 means 30 pixels independant of the density.
If you want a same physical size with a density of 160 you must use 30/120*160 = 40 pixels.
To become density independant you must use ItemHeight = 40dip because the reference density is 160.

Best regards.
 
Last edited:
Upvote 0
Top