2013-07-12 60 views

回答

19
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(); 
} 
+1

+1我正要張貼了同樣的答案 – Sameer

+0

@Sameer感謝它爲我工作在所有應用程序:) – KOTIOS

+2

從Android 3.2(API級別13)開始,這些大小組被棄用,以支持基於可用屏幕寬度管理屏幕大小的新技術。如果您正在開發Android 3.2及更高版本,請參閱爲Android 3.2聲明Tablet Layouts以獲取更多信息。 http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts –