获取屏幕面积的大小使用活动 [英] Get dimension of screen area used by activity

查看:88
本文介绍了获取屏幕面积的大小使用活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何确定的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

这篇关于获取屏幕面积的大小使用活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆