android获取屏幕尺寸

来源:互联网 发布:张兆艺淘宝店 编辑:程序博客网 时间:2024/05/22 05:25
  1. private void getScreenSizeOfDevice2() {  
  2.     Point point = new Point();  
  3.     getWindowManager().getDefaultDisplay().getRealSize(point);  
  4.     DisplayMetrics dm = getResources().getDisplayMetrics();  
  5.     double x = Math.pow(point.x/ dm.xdpi, 2);  
  6.     double y = Math.pow(point.y / dm.ydpi, 2);  
  7.     double screenInches = Math.sqrt(x + y);  
  8.     Log.d(TAG, "Screen inches : " + screenInches);  
  9. }  
1 0