android开发教程之判断是手机还是平板的方法
时间:2022-10-22 12:30:41
方法一
public static boolean isTablet(Context context) {
return (context.getResources().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 = display.getWidth();
// 屏幕高度
float screenHeight = display.getHeight();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
// 屏幕尺寸
double screenInches = Math.sqrt(x + y);
// 大于6尺寸则为Pad
if (screenInches >= 6.0) {
return true;
}
return false;
}
标签:android,手机,平板
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java实现拼图小游戏
2023-03-21 19:58:34
Android实现手指触控图片缩放功能
2021-06-07 17:08:00
![](https://img.aspxhome.com/file/2023/9/106839_0s.jpg)
图文浅析Java序列化和反序列化
2022-08-03 17:46:59
![](https://img.aspxhome.com/file/2023/3/79183_0s.png)
Flink支持哪些数据类型?
2023-01-15 06:55:43
Android实现3D层叠式卡片图片展示
2022-04-22 16:39:19
![](https://img.aspxhome.com/file/2023/4/110744_0s.gif)
java中Executor,ExecutorService,ThreadPoolExecutor详解
2023-10-31 10:50:56
详解Spring框架入门
2023-08-14 12:56:14
![](https://img.aspxhome.com/file/2023/3/69943_0s.png)
SpringBoot从yml配置文件中读常用参数值实例方法
2021-07-01 11:12:04
android仿微信表情雨下落效果的实现方法
2023-07-15 13:44:14
![](https://img.aspxhome.com/file/2023/0/139000_0s.gif)
Springboot定时任务Scheduled重复执行操作
2021-10-08 00:35:54
Android 自定义密码输入框实现代码
2023-02-11 09:18:40
![](https://img.aspxhome.com/file/2023/2/88712_0s.png)
利用 filter 机制给静态资源 url 加上时间戳,来防止js和css文件的缓存问题
2022-03-16 07:51:24
![](https://img.aspxhome.com/file/2023/3/116183_0s.png)
新手初学Java常见排序算法
2022-05-09 03:35:45
web.xml SpringBoot打包可执行Jar运行SpringMVC加载流程
2023-11-24 07:40:52
![](https://img.aspxhome.com/file/2023/9/59929_0s.jpg)
详解SpringSecurity中的Authentication信息与登录流程
2022-01-20 21:36:22
![](https://img.aspxhome.com/file/2023/4/78864_0s.png)
Android UI设计系列之自定义Dialog实现各种风格的对话框效果(7)
2023-11-18 14:26:37
![](https://img.aspxhome.com/file/2023/1/138391_0s.jpg)
java HashMap通过value反查key的代码示例
2022-06-07 08:50:55
Java 改造ayui表格组件实现多重排序
2022-05-15 07:34:15
![](https://img.aspxhome.com/file/2023/1/64891_0s.jpg)
maven引入本地jar包运行报错java.lang.NoClassDefFoundError解决
2022-10-15 01:42:24
java中对List分段操作的实例
2022-12-05 18:38:48