Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

dimensions - How can I get the size of the android application window and not the physical screen size?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

https://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?

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.

Example display height:

// Deprecated
((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;

Or

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...