android获得屏幕高度和宽度(display中getSize(Point)方法使用)
2016-09-20 16:15
447 查看
方法一:
public static int SCREEN_WIDTH;
public static int SCREEN_HEIGHT;
//获取屏幕
WindowManager wm = (WindowManager) getBaseContext().getSystemService(
Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
SCREEN_WIDTH= size.x;
SCREEN_HEIGHT= size.y;
display中getSize(Point)方法使用:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth(); // deprecated
int height = display.getHeight(); // deprecated
查看API 发现:
int getWidth()、int getHeight()方法:(我用的是level 19)
This method was deprecated in API level 13. Use
在看一下getSize(Point)方法:
public void getSize (Point outSize)
Added in API level 13
Gets the size of the display, in pixels.
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.
The size is adjusted based on the current rotation of the display.
The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decoration elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays
Parameters
那么到底怎么使用呢:
方案1:If you want the the display dimensions in pixels you can usegetSize:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
方案2: if you're not in an Activity you can get the default Display viaWINDOW_SERVICE:
display = ((WindowManager)context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();
diswidth = getContext().getResources().getDisplayMetrics().widthPixels;
disheight = getContext().getResources().getDisplayMetrics().heightPixels;
public static int SCREEN_WIDTH;
public static int SCREEN_HEIGHT;
//获取屏幕
WindowManager wm = (WindowManager) getBaseContext().getSystemService(
Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
SCREEN_WIDTH= size.x;
SCREEN_HEIGHT= size.y;
display中getSize(Point)方法使用:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth(); // deprecated
int height = display.getHeight(); // deprecated
查看API 发现:
int getWidth()、int getHeight()方法:(我用的是level 19)
This method was deprecated in API level 13. Use
getSize(Point)instead.
在看一下getSize(Point)方法:
public void getSize (Point outSize)
Added in API level 13
Gets the size of the display, in pixels.
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.
The size is adjusted based on the current rotation of the display.
The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decoration elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays
Parameters
outSize | A Pointobject to receive the size information. |
---|
方案1:If you want the the display dimensions in pixels you can usegetSize:
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
方案2: if you're not in an Activity you can get the default Display viaWINDOW_SERVICE:
display = ((WindowManager)context.getSystemService(context.WINDOW_SERVICE)).getDefaultDisplay();
diswidth = getContext().getResources().getDisplayMetrics().widthPixels;
disheight = getContext().getResources().getDisplayMetrics().heightPixels;
相关文章推荐
- Android获取屏幕分辨率及DisplayMetrics简介 和java获得屏幕宽度高度的方法
- Android获得屏幕高度和宽度的两种方法
- android获得屏幕高度和宽度四种方法
- android获得屏幕高度和宽度的方法
- android获得屏幕高度和宽度
- android 获取屏幕高度和宽度 的方法
- android获得屏幕高度和宽度
- android 获取屏幕高度和宽度的方法
- android 获取屏幕高度和宽度的方法
- android 获取屏幕高度和宽度 的方法
- android获得屏幕高度和宽度
- Android中获取屏幕高度与宽度的两种方法
- android获取屏幕高度和宽度的实现方法
- android获得手机屏幕状态栏高度 屏幕高宽度
- android获得屏幕高度和宽度
- android获得屏幕高度和宽度
- android获得屏幕高度和宽度
- android获取屏幕高度和宽度 的方法
- android 获取屏幕高度和宽度的方法
- android获得屏幕高度和宽度