AndroidUtilCode icon indicating copy to clipboard operation
AndroidUtilCode copied to clipboard

SizeUtils.java 实际是用没效果,我用这个才可以

Open jimmonster opened this issue 7 years ago • 1 comments

public class AutoSizeUtils {

private AutoSizeUtils() {
    throw new IllegalStateException("you can't instantiate me!");
}

public static int dp2px(Context context, float value) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, context.getResources().getDisplayMetrics()) + 0.5f);
}

public static int sp2px(Context context, float value) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, value, context.getResources().getDisplayMetrics()) + 0.5f);
}

public static int pt2px(Context context, float value) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, value, context.getResources().getDisplayMetrics()) + 0.5f);
}

public static int in2px(Context context, float value) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_IN, value, context.getResources().getDisplayMetrics()) + 0.5f);
}

public static int mm2px(Context context, float value) {
    return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, value, context.getResources().getDisplayMetrics()) + 0.5f);
}

}

jimmonster avatar Aug 20 '19 08:08 jimmonster

试试 1.25.9 版本

Blankj avatar Aug 26 '19 02:08 Blankj