Created
January 23, 2015 17:05
-
-
Save juliomarcos/6e86cc8fda4fa6553b80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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