Last active
March 3, 2016 08:52
-
-
Save jimbray/b77ba283541e6829d39d to your computer and use it in GitHub Desktop.
判断设备是否是 Tablet,适配Tablet设备的时候特别有用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 判断是否是 Tablet | |
* | |
* @param activity Activity | |
* @return true, if is tablet device | |
*/ | |
public static boolean isTablet(Activity activity) { | |
DisplayMetrics dm = new DisplayMetrics(); | |
activity.getWindowManager().getDefaultDisplay().getMetrics(dm); | |
double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels, 2) + Math.pow(dm.heightPixels, 2)); | |
double screenSize = diagonalPixels / (160 * dm.density); | |
return screenSize >= 6.0D; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment