屏幕尺寸和设备方向
Screen size and device orientation
我正在处理与常见屏幕尺寸检测和设备方向相关的任务。
是否有任何内置解决方案可以在运行时检测屏幕尺寸(正常、大、超大)而不向资源文件添加内容?
Check Device Orientation
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT){
}else if(orientation == Configuration.ORIENTATION_LANDSCAPE){}
Screen size detection
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { // Large screen
} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { //Normal sized screen
} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {//Small sized screen
} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {//XLarge sized screen}
我正在处理与常见屏幕尺寸检测和设备方向相关的任务。
是否有任何内置解决方案可以在运行时检测屏幕尺寸(正常、大、超大)而不向资源文件添加内容?
Check Device Orientation
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT){
}else if(orientation == Configuration.ORIENTATION_LANDSCAPE){}
Screen size detection
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { // Large screen
} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { //Normal sized screen
} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {//Small sized screen
} else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {//XLarge sized screen}