Skip to content

Instantly share code, notes, and snippets.

@zeeshanaslam78
Created January 7, 2018 21:43
Show Gist options
  • Save zeeshanaslam78/0e49fcdd9a966e014ec622dec03fb265 to your computer and use it in GitHub Desktop.
Save zeeshanaslam78/0e49fcdd9a966e014ec622dec03fb265 to your computer and use it in GitHub Desktop.
Convert dp to px an px to dp in Android
public static int dpToPx(int dp)
{
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}
public static int pxToDp(int px)
{
return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment