在实际应用中,需要一个全屏的高度,一般都要去掉状态栏(HOME键以及BACK等键)的高度
获取设备的屏幕大小,一般为:
private void getScreenWh(){
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = this.getResources().getDisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
}
获取状态栏的高度为:
private int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height",
"dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}