android开发教程之判断是⼿机还是平板的⽅法⽅法⼀
复制代码代码如下:
public static boolean isTablet(Context context) {
return (Resources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK)
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
⽅法⼆
通过计算设备尺⼨⼤⼩的⽅法来判断是⼿机还是平板:
复制代码代码如下:
/**
* 判断是否为平板
*
* @return
*/
private boolean isPad() {
WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
// 屏幕宽度
float screenWidth = Width();
// 屏幕⾼度
float screenHeight = Height();
DisplayMetrics dm = new DisplayMetrics();
double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
android学习教程// 屏幕尺⼨
double screenInches = Math.sqrt(x + y);
// ⼤于6尺⼨则为Pad
if (screenInches >= 6.0) {
return true;
}
return false;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。