-2

我正在使用这个厚,但它返回“0”

    View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    int viewHeight = content.getHeight();

怎么做?

4

3 回答 3

3
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);
}
});
于 2013-09-21T07:01:51.530 回答
0

根据我接下来探索的多莉的回答:

            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;
于 2014-06-18T18:34:21.923 回答
-2
//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();
于 2013-05-13T03:55:15.987 回答