我有以下代码来查找屏幕的大小:
WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
Point size = new Point();
int measuredWidth = 0;
int measuredHeight = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
wm.getDefaultDisplay().getSize(size);
measuredWidth = size.x;
measuredHeight = size.y;
} else {
Display display = wm.getDefaultDisplay();
measuredWidth = display.getWidth();
measuredHeight = display.getHeight();
}
在galaxy gio(2.3.6)上这是可行的,但是在galaxy tab 10.1(3.0)上会崩溃。
wm.getDefaultDisplay().getSize(size);
在这条线上我得到
NoSuchMethodError:android.view.Display.getSize。
我怎样才能解决这个问题?