在Android中,有时我们要获取屏幕的大小,有时要获取状态栏的高度,下面就是一下获取的方法。
/**
* 得到屏幕大小
*/
protected void getAreaScreen() {
Display display = getWindowManager().getDefaultDisplay();
Point outP = new Point();
display.getSize(outP);
Log.d(TAG, "AreaScreen:" + " width=" + outP.x + " height=" + outP.y);
}
/**
* 得到应用的大小
*/
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() {
// 用户绘制区域
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());
}
/**
* 设置View的Padding
*/
protected void setPadding(View v, int left, int top, int right, int bottom) {
v.setPadding(left, top, right, bottom);
v.requestLayout();
}