獲取狀態(tài)欄高度
//獲取status_bar_height資源的ID
intresourceId = getResources().getIdentifier("status_bar_height","dimen","android");
if(resourceId >0) {
//根據(jù)資源ID獲取響應的尺寸值
intstatusBarHeight = getResources().getDimensionPixelSize(resourceId);
SPUtils.putInt(Constant.STATUSBAR_HEIGHT,statusBarHeight);
}
動態(tài)設置控件高度
intstatusBarHeight = SPUtils.getInt(Constant.STATUSBAR_HEIGHT,0);
if(statusBarHeight >0) {
LinearLayout.LayoutParams sp_params =newLinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
sp_params.height= statusBarHeight;
mvView.setLayoutParams(sp_params);
}
務必保持一致 (?LinearLayout.?LinearLayout.LayoutParams 與需要設置的控件父控件)