在Android中,有時我們要獲取屏幕的大小庞瘸,有時要獲取狀態(tài)欄的高度捧弃,下面就是一下獲取的方法。
/**
* 得到屏幕大小
*/
protected void getAreaScreen() {
Display display = getWindowManager().getDefaultDisplay();
Point outP = new Point();
display.getSize(outP);
Log.d(TAG, "AreaScreen:" + " width=" + outP.x + " height=" + outP.y);
}
/**
* 得到應(yīng)用的大小
*/
protected void getAreaApplication() {
Rect outRect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
statusHeight = outRect.top;
applicationHeight = outRect.height();
Log.d(TAG, "AreaApplication:" + " width=" + outRect.width()
+ " height=" + outRect.height() + " top=" + outRect.top
+ " bottom=" + outRect.bottom);
}
/**
* 得到View繪制的大小
*/
protected void getAreaView() {
// 用戶繪制區(qū)域
Rect outRect = new Rect();
getWindow().findViewById(Window.ID_ANDROID_CONTENT).getDrawingRect(outRect);
viewHeight = outRect.height();
Log.d(TAG, "AreaView:" + " width=" + outRect.width() + " height="
+ outRect.height());
}
/**
* 設(shè)置View的Padding
*/
protected void setPadding(View v, int left, int top, int right, int bottom) {
v.setPadding(left, top, right, bottom);
v.requestLayout();
}