方法一:

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中。

更多相关文章

  1. Android使用httpPost向服务器发送请求的方法
  2. android中Bitmap图像处理 修改图片大小以及保存时的文件大小
  3. 设置图片缩放方法失效 解决办法设置android:scaleType属性
  4. android 写布局的时候注意大小写
  5. XAMARIN Android获取WIFIMAC地址的方法
  6. 实时获取Android 各版本电量的统一方法
  7. 利用浏览器默认方法获取浏览器当前位置
  8. 【Android】实现Activity页面暂停几秒后跳转的两种方法

随机推荐

  1. Android名称、版本和API level的对应关系
  2. android:gallery相册
  3. android 文件系统分析
  4. Android中Gallery来显示图片
  5. Android(安卓)View绘制机制
  6. Android(安卓)training
  7. Android之UtilsRequesServicetHelp工具类
  8. Android图片按比例缩放
  9. Android(安卓)同步请求导致系统崩溃andro
  10. android aidl service