2015-11-03 150 views
0

我正在处理与通用屏幕尺寸检测和设备方向有关的任务。屏幕尺寸和设备方向

是否有任何内置的解决方案来检测运行时的屏幕大小(正常,大,xlarge)而无需向资源文件添加内容?

+0

为什么你需要得到屏幕大小在谷歌屏幕桶的条款? – Nanoc

回答

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}