2013-11-26 28 views
1

我計算設備的屏幕尺寸爲編程平板nexus7" ,它讓6.7。但Nexus7" 有屏幕尺寸7" 我想要得到設備的完整的屏幕尺寸 這裏是我的代碼: - 。如何在android中以編程方式獲取設備的完整屏幕大小?

DisplayMetrics dm = new DisplayMetrics(); 
     getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); 
     double x = Math.pow(dm.widthPixels/dm.xdpi, 2); 
     double y = Math.pow(dm.heightPixels/dm.ydpi, 2); 
     screenInches = Math.sqrt(x + y); 

回答

2

嘗試如下

int screenSize = getResources().getConfiguration().screenLayout & 
     Configuration.SCREENLAYOUT_SIZE_MASK; 

switch(screenSize) { 
    case Configuration.SCREENLAYOUT_SIZE_LARGE: 
     Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show(); 
     break; 
    case Configuration.SCREENLAYOUT_SIZE_NORMAL: 
     Toast.makeText(this, "Normal screen",Toast.LENGTH_LONG).show(); 
     break; 
    case Configuration.SCREENLAYOUT_SIZE_SMALL: 
     Toast.makeText(this, "Small screen",Toast.LENGTH_LONG).show(); 
     break; 
    default: 
     Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show(); 
} 
+0

我在我的應用程序獲得的屏幕尺寸。 – amita

+0

@amita請編輯答案 – Tombeau

+0

我需要英寸的屏幕尺寸。 – amita

相關問題