android 在Activity下获取getWindowManager()的屏幕尺寸和自定义View下的获取尺寸

来源:互联网 发布:88gbgb的新域名 编辑:程序博客网 时间:2024/05/17 06:36

1. 在activity下的获取屏幕尺寸,相信大家都熟悉:

WindowManager wm=this.getWindowManager();

int width = wm.getDefaultDisplay().getWidth();

int height = wm.getDefaultDisplay().getHeight();

2 . 不在activity情况下也就是在自定义的View下的获取屏幕尺寸如下:

  Rect rect = new Rect();

this.getWindowVisibleDisplayFrame(rect);
int width  = rect.width();
int height = rect.height();
0 0
原创粉丝点击