我怎样才能获取Android应用程序窗口的大小,而不是实际的屏幕尺寸?应用程序、而不是、实际、大小

2023-09-05 03:38:47 作者:人情冷暖薄如纸

在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:

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.