Created
January 24, 2012 16:11
-
-
Save tai2/1670883 to your computer and use it in GitHub Desktop.
TypedValue#applyDimension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static float applyDimension(int unit, float value, | |
DisplayMetrics metrics) | |
{ | |
switch (unit) { | |
case COMPLEX_UNIT_PX: | |
return value; | |
case COMPLEX_UNIT_DIP: | |
return value * metrics.density; | |
case COMPLEX_UNIT_SP: | |
return value * metrics.scaledDensity; | |
case COMPLEX_UNIT_PT: | |
return value * metrics.xdpi * (1.0f/72); | |
case COMPLEX_UNIT_IN: | |
return value * metrics.xdpi; | |
case COMPLEX_UNIT_MM: | |
return value * metrics.xdpi * (1.0f/25.4f); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment