我正在处理与常见屏幕尺寸检测和设备方向相关的任务。
是否有任何内置的解决方案可以在运行时检测屏幕大小(正常,大,xlarge)而无需向资源文件添加内容?
答案 0 :(得分:2)
检查设备方向
int orientation = getResources().getConfiguration().orientation;
if(orientation == Configuration.ORIENTATION_PORTRAIT){
}else if(orientation == Configuration.ORIENTATION_LANDSCAPE){}
屏幕尺寸检测
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}