我怎样才能获取Android应用程序窗口的大小,而不是实际的屏幕尺寸? [英] How can I get the size of the android application window and not the physical screen size?

查看:851
本文介绍了我怎样才能获取Android应用程序窗口的大小,而不是实际的屏幕尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的,我怎么能获取应用程序窗口的大小?我不是在寻找的物理屏幕尺寸,但屏幕上的应用程序窗口的实际大小。例如。一般还剩下些什么之后,你拿走了通知栏,柔软的触感按钮等。

In Android, how can I get the size of the app window? I'm NOT looking for the physical screen size, but the actual size of the applications window on the screen. E.g. generally what's left after you take away the notification bar, soft touch buttons, etc.

推荐答案

如果您希望您的应用程序窗口,你可以叫yourview.getHeight()和yourview.getWidth()的大小;但认为必须制定该工作。

If you want the size of your app's window you can just call yourview.getHeight() and yourview.getWidth(); But the view must be drawn for that to work.

如果你想获得的高度之前,它的绘制,你可以这样做:

If you want to get the height before it's drawn you can do this:

<一个href="http://stackoverflow.com/a/10134260/1851478">http://stackoverflow.com/a/10134260/1851478

有很多画面/观测量的不同情况,所以当你能具体谈谈应用程序窗口的实际大小,这是你的应用程序?或者主屏幕的应用程序?一些其他的应用程序?

There are a lot of different cases of screen/view measurement though, so if you could be more specific about "actual size of applications window", is this your app? Or the home screen app?, some other app?

如果您想可用空间减去装饰品(状态栏/软按钮),你可以在反向攻击它为好,例如测量实际屏幕尺寸(该方法也不尽相同通过API),然后减去地位的高度酒吧。

If you want usable space minus decorations (status bar/soft button), you can attack it in reverse as well, for example measuring the actual screen dimensions (the methods vary by API), and then subtract the height of the status bar.

示例显示高度:

((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();

状态栏的高度:

status bar height:

Rect rectgle= new Rect();
Window window= getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int StatusBarHeight= rectgle.top;

int statusBarHeight = Math.ceil(25 * context.getResources().getDisplayMetrics().density);

许多不同的方式来做到这一点。

Many different ways to do this.

当然,需要您提供更多信息,虽然给出更准确的答案。

Certainly need more info from you though to give a more accurate answer.

这篇关于我怎样才能获取Android应用程序窗口的大小,而不是实际的屏幕尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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