package com.werb.gankwithzhihu.util; import android.content.Context; /** * Created by Werb on 2016/7/26. * Werb is Wanbo. * Contact Me : werbhelius@gmail.com * Utils of Screen , dip , px */ public class ScreenUtil { private static ScreenUtil mScreenTools; private Context context; private ScreenUtil(Context context) { this.context = context.getApplicationContext(); } public static ScreenUtil instance(Context context) { if (mScreenTools == null) mScreenTools = new ScreenUtil(context); return mScreenTools; } public int dip2px(float f) { return (int) (0.5D + (double) (f * getDensity(context))); } public int dip2px(int i) { return (int) (0.5D + (double) (getDensity(context) * (float) i)); } public int get480Height(int i) { return (i * getScreenWidth()) / 480; } public float getDensity(Context context) { return context.getResources().getDisplayMetrics().density; } public int getScal() { return (100 * getScreenWidth()) / 480; } public int getScreenDensityDpi() { return context.getResources().getDisplayMetrics().densityDpi; } public int getScreenHeight() { return context.getResources().getDisplayMetrics().heightPixels; } public int getScreenWidth() { return context.getResources().getDisplayMetrics().widthPixels; } public float getXdpi() { return context.getResources().getDisplayMetrics().xdpi; } public float getYdpi() { return context.getResources().getDisplayMetrics().ydpi; } public int px2dip(float f) { float f1 = getDensity(context); return (int) (((double) f - 0.5D) / (double) f1); } public int px2dip(int i) { float f = getDensity(context); return (int) (((double) i - 0.5D) / (double) f); } }