Skip to content

Instantly share code, notes, and snippets.

@blork
Created May 21, 2013 14:49
Show Gist options
  • Save blork/5620386 to your computer and use it in GitHub Desktop.
Save blork/5620386 to your computer and use it in GitHub Desktop.
Convert DP (display independent pixels) to pixels.
public static int dp2px(final float dps, final Resources res) {
final float scale = res.getDisplayMetrics().density;
final int pixels = (int) ((dps * scale) + 0.5f);
return pixels;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment