Android获取屏幕的高度和宽度
16lz
2021-01-23
方法一:
DisplayMetrics metrics=new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(metrics);int width=metrics.widthPixels;//屏幕的宽度int height=metrics.heightPixels;//屏幕的高度
方法二:
Display display=getWindowManager.getDefaultDisplay();Point point=new Point();display.getSize(point);int width=point.x;int height=point.y;
getSize()方法的说明:
Note that this value should not be used for computing layouts, since a device will typically have screen decoration (such as a status bar) along the edges of the display that reduce the amount of application space available from the size returned here. Layouts should instead use the window size。
大体意思是这个方法不能用来计算布局大小,因为屏幕上的边缘的status bar等装饰减少了实际可获得的屏幕空间,而getSize方法是将减少后的屏幕大小的信息存入了Point中。
更多相关文章
- Android使用httpPost向服务器发送请求的方法
- android中Bitmap图像处理 修改图片大小以及保存时的文件大小
- 设置图片缩放方法失效 解决办法设置android:scaleType属性
- android 写布局的时候注意大小写
- XAMARIN Android获取WIFIMAC地址的方法
- 实时获取Android 各版本电量的统一方法
- 利用浏览器默认方法获取浏览器当前位置
- 【Android】实现Activity页面暂停几秒后跳转的两种方法