我动态获取屏幕高度的代码:
Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
错误:错误:java.lang.ClassCastException:android.app.Application 完整日志猫: http: //pastebin.com/8zUNFUYn
编辑:将代码更改为:
Display display = (activity).getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
工作但是,给出了一个新错误,即 display.getSize(size) is not a method。该 API 是否已弃用?