android获取屏幕的高度和宽度

来源:互联网 发布:哥特式lolita淘宝 编辑:程序博客网 时间:2024/06/06 02:30

转载自: https://www.cnblogs.com/pswzone/archive/2012/03/11/2389993.html


android获取屏幕的高度和宽度用到WindowManager这个类,两种方法: 

 
1、WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();
 
2、WindowManager wm = this.getWindowManager();
 
     int width = wm.getDefaultDisplay().getWidth();
     int height = wm.getDefaultDisplay().getHeight();