Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int DIP_VALUE = 5;
- int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DIP_VALUE, getResources().getDisplayMetrics());
- //or simply
- float pixels = getResources().getDimensionPixelSize(DIP_VALUE);
- mTextView.setTextSize(pixels);
- public static float getDipFromPixels(float px) {
- return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, px, Resources.getSystem().getDisplayMetrics());
- }
- public static float getPixelsFromDip(float dip) {
- return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, Resources.getSystem().getDisplayMetrics());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement