Skip to content

Instantly share code, notes, and snippets.

@juliomarcos
Created January 23, 2015 17:05
Show Gist options
  • Save juliomarcos/6e86cc8fda4fa6553b80 to your computer and use it in GitHub Desktop.
Save juliomarcos/6e86cc8fda4fa6553b80 to your computer and use it in GitHub Desktop.
import android.content.Context;
public class ScalingUtils {
public static int dpToPx(final Context context, final float dp) {
// Took from http://stackoverflow.com/questions/8309354/formula-px-to-dp-dp-to-px-android
final float scale = context.getResources().getDisplayMetrics().density;
return (int) ((dp * scale) + 0.5f);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment