1、导航栏隐藏问题,计算高度出现失误
老方法:
Context context = getApplicationContext();
DisplayMetrics localDisplayMetrics = context.getResources().getDisplayMetrics();
// 获取高度
int height = localDisplayMetrics.heightPixels;
// 获取宽度
int width = localDisplayMetrics.widthPixels;
4.2以后采用,可正确计算
Context context = getApplicationContext();
DisplayMetrics dm = new DisplayMetrics();
WindowManager windowMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
windowMgr.getDefaultDisplay().getRealMetrics(dm);
// 获取高度
int height = dm.heightPixels;
// 获取宽度
int width = dm.widthPixels;