Loading

android 入门-控件 测量状态栏高度

private ViewTreeObserver viewTreeObserver;

 

/** 获取可見区域高度 **/
WindowManager manager = getWindowManager();
window_width = manager.getDefaultDisplay().getWidth();
window_height = manager.getDefaultDisplay().getHeight();

 

viewTreeObserver = dragImageView.getViewTreeObserver();
viewTreeObserver
.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

@Override
public void onGlobalLayout() {
if (state_height == 0) {
// 获取状况栏高度
Rect frame = new Rect();
getWindow().getDecorView()
.getWindowVisibleDisplayFrame(frame);
state_height = frame.top;
dragImageView.setScreen_H(window_height-state_height);
dragImageView.setScreen_W(window_width);
}

}
});

posted @ 2015-09-29 11:00  androllen  阅读(263)  评论(0编辑  收藏  举报