首页 > 代码库 > Display中getHeight()和getWidth() 官方废弃
Display中getHeight()和getWidth() 官方废弃
今天使用Display获取屏幕的宽和高时出现下面的提示:
Display dp=getWindowManager().getDefaultDisplay(); int Height=dp.getHeight(); ---->The method getHeight() from the type Display is deprecated int Width=dp.getWidth(); ---->The method getWidth() from the type Display is deprecated
官方解释:
int getHeight() This method was deprecated in API level 13. Use getSize(Point) instead. int getWidth() This method was deprecated in API level 13. Use getSize(Point) instead. http://developer.android.com/reference/android/view/Display.html
替代的方法:
DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH = dm.widthPixels; SCREEN_HEIGHT = dm.heightPixels;
解析heightPixels和widthPixels:
public int heightPixels The absolute height of the display in pixels.
public int widthPixels The absolute width of the display in pixels.
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。