Convert dp to pixel

public static int convertDpToPixel(float dp){
    DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
    float px = dp * (metrics.densityDpi / 160f);
    return Math.round(px);
}

Also published on Medium.

By |2019-04-05T09:42:56+00:00March 14th, 2019|Categories: Android Tips|Tags: |0 Comments

Leave A Comment