pixels to dp util method

This commit is contained in:
gorodeckii 2017-05-29 12:20:10 +03:00
parent fb063afb95
commit 14e70c5ccf
1 changed files with 4 additions and 0 deletions

View File

@ -200,6 +200,10 @@ public final class UiUtils {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInDp, getDisplayMetrics(context));
}
public static int pixelsToDp(@NonNull final Context context, final int pixels) {
return (int) (pixels * getDisplayMetrics(context).density + 0.5f);
}
private OfMetrics() {
}