Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Why does getDimension and getDimensionPixelSize both return the same?

I find the methods getDimension and getDimensionPixelSize confusing.

It would look to me as though getDimension would return the actual value stored in the dimension, for example 10dp and getDimensionPixelSize would return it converted to px.

But both seem to do the same thing...

like image 866
user3591115 Avatar asked Jul 01 '14 23:07

user3591115


1 Answers

getDimension() returns a floating point number which is the dimen value adjusted with current display metrics:

getDimensionPixelSize() returns an integer. It is the same as getDimension() rounded to an int with any non-zero dimension ensured to be at least one pixel in size.

For integer dimension values they both return the same numeric value.

like image 93
laalto Avatar answered Oct 05 '22 23:10

laalto