获取屏幕面积的大小使用活动屏幕、面积、大小

由网友(笑谈浮生流年)分享简介:我如何确定的onCreate在活动的尺寸(宽度和高度)。尺寸必须不使整个屏幕的而仅仅是所使用的活动区域。有几个方法我试过贴在SO都最终给该设备的最大屏幕尺寸。How do I determine the dimensions (width and height) of an activity during onCre...

我如何确定的onCreate在活动的尺寸(宽度和高度)。尺寸必须不使整个屏幕的而仅仅是所使用的活动区域。有几个方法我试过贴在SO都最终给该设备的最大屏幕尺寸。

How do I determine the dimensions (width and height) of an activity during onCreate. The dimension must not be that of the entire screen but only of area that is used by the activity. A few methods I tried posted on SO all end up giving the device's maximum screen sizes.

推荐答案

您是否尝试过(不完全的onCreate):

Have you tried (not exactly onCreate):

activityRootView = findViewById(R.id.yourRootView);    
        activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                   //activityRootView.getHeight();
                   //...
                }
             }
        });

和ofcourse,您activitys主要布局必须符合父母或填写内容

And ofcourse, your activitys main layout has to match parent or fill content

阅读全文

相关推荐

最新文章