Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bulwinkel
Created August 18, 2016 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bulwinkel/6eb495c23aca61f6ae14cd190b5062ed to your computer and use it in GitHub Desktop.
Save bulwinkel/6eb495c23aca61f6ae14cd190b5062ed to your computer and use it in GitHub Desktop.
Android TypedValue Utilities (px -> dp)
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