Answers for "pixel to dp"

0

pixel to dp

public static float dpFromPx(final Context context, final float px) {
    return px / context.getResources().getDisplayMetrics().density;
}

public static float pxFromDp(final Context context, final float dp) {
    return dp * context.getResources().getDisplayMetrics().density;
}
Posted by: Guest on June-03-2021

Browse Popular Code Answers by Language