当时因为这个问题还有个头痛的bug,视频会议中,几个surfaceView发生遮挡问题,因为小哥计算高度的时候用的第二种方法
//获取手机的真实宽高,包括状态栏和导航栏的高度
android.view.Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getRealSize(size);//这里为getSize获得的是app分辨率
videoWidth = size.x;
videoHeight = size.y;
//获取的值根据状态栏和导航栏的高度变化而变化
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int width = metric.widthPixels; // 屏幕宽度(像素)
int height = metric.heightPixels; // 屏幕高度(像素)
float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5)
int densityDpi = metric.densityDpi; // 屏幕密度DPI(1
//以下两个方法不准:打印结果是导航栏在设置里面不论关否,都返回true;并且返回的高度包含状态栏的高度,开启导航栏是220,关闭导航栏是90
/**
* 获取是否存在NavigationBar
* @param context
* @return
*/
public boolean checkDeviceHasNavigationBar(Context context) {
boolean hasNavigationBar = false;
Resources rs = context.getResources();
int id = rs.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
hasNavigationBar = rs.getBoolean(id);
}
try {
Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
Method m = systemPropertiesClass.getMethod("get", String.class);
String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
if ("1".equals(navBarOverride)) {
hasNavigationBar = false;
} else if ("0".equals(navBarOverride)) {
hasNavigationBar = true;
}
} catch (Exception e) {
}
return hasNavigationBar;
}
/**
* 获取虚拟功能键高度
* @param context
* @return
*/
public int getVirtualBarHeigh(Context context) {
int vh = 0;
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
try {
@SuppressWarnings("rawtypes")
Class c = Class.forName("android.view.Display");
@SuppressWarnings("unchecked")
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
vh = dm.heightPixels - windowManager.getDefaultDisplay().getHeight();
} catch (Exception e) {
e.printStackTrace();
}
return vh;
}