Created
July 4, 2012 11:26
-
-
Save fidanov/3046864 to your computer and use it in GitHub Desktop.
Android: DIP 2 PX programmatically. Works on any device with any density. Useful when settings width and height in code.
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; | |
import android.util.TypedValue; | |
public class Util { | |
public static int dp(Context context, int size) { | |
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, | |
size, | |
context.getResources().getDisplayMetrics()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment