android获取屏幕的宽度和高度用到了WindowManager这个类,下面介绍如何获取屏幕的宽度和高度
1、WindowManager windowManager = (WindowManager) getContext()
.getSystemService(Context.WINDOW_SERVICE);
int width = windowManager.getDefaultDisplay().getWidth();
int height = windowManager.getDefaultDisplay().getHeight();
这种方式的参考来源为:http://developer.android.com/reference/android/view/WindowManager.html
The interface that apps use to talk to the window manager.
Use Context.getSystemService(Context.WINDOW_SERVICE)
to get one of these.
2、WindowManager windowManager = activity.this.getWindowManager();
int width = windowManager.getDefaultDisplay().getWidth();
int height = windowManager.getDefaultDisplay().getHeight();
这种方式是因为Activity提供了一个getWindowManager方法!