ulfben icon

DIP to Pixel (Android)

ulfben | PRO | 01/08/17 06:13:21 PM UTC | 0 ⭐ | 784 👁️ | Never ⏰ | []
Java |

590 B

|

None

|

0 👍

/

0 👎

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());
}

Comments

  • Rteuixl icon
    04/02/26 04:51:32 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎