当前位置: 代码迷 >> Android >> Android 获取银屏尺寸
  详细解决方案

Android 获取银屏尺寸

热度:53   发布时间:2016-05-01 15:53:25.0
Android 获取屏幕尺寸
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;
}


另外一种方法是:

   WindowManager windowManager = getWindowManager();
   Display display = windowManager.getDefaultDisplay();
   ANDROID_WIDTH = display.getWidth();
   ANDROID_HEIGHT = display.getHeight();
  相关解决方案