我正在使用这个厚,但它返回“0”
View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
int viewHeight = content.getHeight();
怎么做?
我正在使用这个厚,但它返回“0”
View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
int viewHeight = content.getHeight();
怎么做?
root = (ViewGroup)findViewById(R.id.root);
root.post(new Runnable() {
public void run(){
Rect rect = new Rect();
Window win = getWindow();
win.getDecorView().getWindowVisibleDisplayFrame(rect);
int statusHeight = rect.top;
int contentViewTop = win.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleHeight = contentViewTop - statusHeight;
Log.w("dimens_tag", "title = " + titleHeight + " status bar = " + statusHeight);
}
});
根据我接下来探索的多莉的回答:
Window win = getWindow();
topBarHeight = win.findViewById(Window.ID_ANDROID_CONTENT).getTop();;
Rect rect = new Rect();
win.getDecorView().getWindowVisibleDisplayFrame(rect);
if (rect.top==0){
//pad
int resourceId = getResources().getIdentifier("status_bar_height","dimen", "android");
if (resourceId > 0)
bottomBarHeight=getResources().getDimensionPixelSize(resourceId);
} else
bottomBarHeight=0;
//Returns the size of the entire window, including status bar and title.
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
//Try to find the dimension of the view without the status/title bars.
int iViewHeight = mvMountain.getHeight();
int iViewWidth = mvMountain.getWidth();