Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measure text returns float value

Tags:

android

It is a stupid question, probably... However, what is the unit of measure of the measureText() value returned? I need the width of a text in px. I thought px, dp, sp would be integer values. So why measureText() in TextPaint returns a float value?

like image 600
Daniele Vitali Avatar asked Aug 26 '26 00:08

Daniele Vitali


1 Answers

Why would the return type not be a float, representhing pixels?

Drawing on screen uses floats all the way down to the GPU level. This makes calculations more convenient and makes it possible to use antialiasing and subpixel rendering.

Dimensions such as px, dp, sp are floats too, though there are convenience methods to get an integer pixel size value.

like image 195
laalto Avatar answered Aug 28 '26 15:08

laalto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!