獲取手機屏幕大小代碼

         public static String getDisplayMetrics(Context cx) {
                String str = "";
                DisplayMetrics dm = new DisplayMetrics();
                dm = cx.getApplicationContext().getResources().getDisplayMetrics();
                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;
        }
發佈了23 篇原創文章 · 獲贊 4 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章