Created
January 28, 2015 13:30
-
-
Save vbarthel-fr/343b10d9d748f0b267c9 to your computer and use it in GitHub Desktop.
View utils
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
/** | |
* Convert a value from dip to pixel. | |
* | |
* @param displayMetrics the {@link android.util.DisplayMetrics} used to convert. | |
* @param dip the value in dip to convert. | |
* @return a value in pixel. | |
*/ | |
public static int dipToPx(DisplayMetrics displayMetrics, float dip) { | |
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, displayMetrics); | |
} |
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
/** | |
* Convert a value from sp to pixel. | |
* | |
* @param displayMetrics the {@link android.util.DisplayMetrics} used to convert. | |
* @param sp the value in sp to convert. | |
* @return a value in pixel. | |
*/ | |
public static float spToPx(DisplayMetrics displayMetrics, float sp) { | |
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, displayMetrics); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment