Skip to content

Instantly share code, notes, and snippets.

@JonathandelaSen
Created September 5, 2017 14:45
Show Gist options
  • Save JonathandelaSen/6c6131ffa691dabbb9a000a647c3d270 to your computer and use it in GitHub Desktop.
Save JonathandelaSen/6c6131ffa691dabbb9a000a647c3d270 to your computer and use it in GitHub Desktop.
public class DpsPxsConversion {
public static float dpFromPx(final Context context, float px) {
return px / context.getResources().getDisplayMetrics().density;
}
public static float pxFromDp(final Context context, float dp) {
return dp * context.getResources().getDisplayMetrics().density;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment