利用DisplayMetrics获取屏幕信息

来源:互联网 发布:艾瑞mut监测数据 编辑:程序博客网 时间:2024/05/21 22:00

public static String getDisplayMetrics(Context cx) {        String str = "";        DisplayMetrics dm = new DisplayMetrics();        //取得DisplayMetrics对象方法一        //dm = cx.getApplicationContext().getResources().getDisplayMetrics();        //取得DisplayMetrics对象方法二       ((Activity)cx).getWindowManager().getDefaultDisplay().getMetrics(dm);       int screenWidth = dm.widthPixels;        int screenHeight = dm.heightPixels;        float density = dm.density;        float xdpi = dm.xdpi;        float ydpi = dm.ydpi;              str += "The absolute width:" + String.valueOf(screenWidth) + "pixels\n";        str += "The absolute heightin:" + String.valueOf(screenHeight) + "pixels\n";        str += "The logical density of the display.:" + String.valueOf(density)        + "\n";        str += "X dimension :" + String.valueOf(xdpi) + "pixels per inch\n";        str += "Y dimension :" + String.valueOf(ydpi) + "pixels per inch\n";              return str;     }