标签:
几乎每个app都会用到屏幕相关的属性,所以我在这将常用的属性封装成了工具类
首先新建一个工具类(ScreenUtils)
1.获取屏幕宽高:
public static DisplayMetrics getScreenSize(Context context){ DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager)context .getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); display.getMetrics(metrics); return metrics; }
2.屏幕density(密度)
public static float getDeviceDensity(Context context){ DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager)context .getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); return metrics.density; }
标签:
原文地址:http://www.cnblogs.com/cxsy/p/5597697.html