Skip to content

Instantly share code, notes, and snippets.

@kevinthecity
Created February 27, 2014 20:33
Show Gist options
  • Save kevinthecity/9258945 to your computer and use it in GitHub Desktop.
Save kevinthecity/9258945 to your computer and use it in GitHub Desktop.
/**
* Converts a DP value to a PX value.
*
* @param context
* the context to use.
* @param dp
* the DP value to convert.
* @return the converted PX value.
*/
public static int getPxFromDp(Context context, float dp) {
if(context == null)
return 0;
return (int) (context.getResources().getDisplayMetrics().density * dp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment