Created
August 18, 2016 13:11
-
-
Save bulwinkel/6eb495c23aca61f6ae14cd190b5062ed to your computer and use it in GitHub Desktop.
Android TypedValue Utilities (px -> dp)
This file contains hidden or 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; | |
import android.util.TypedValue; | |
public class TypedValues { | |
private TypedValues() { | |
//no instances | |
} | |
public static int dip(Context context, float dp) { | |
return (int)dp(context, dp); | |
} | |
public static float dp(Context context, float dp) { | |
return TypedValue.applyDimension( | |
TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment