Android: display dimensions available for Activity

In this tutorial you will learn how to check the space allowed for Activity to draw content in, this is useful when you have to make calculations of UI elements based on width and heigh.



Inside Activity


Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
System.out.println("width = " + width + ", height = " + height);




I/System.out( 2318): width = 1280, height = 752

Note that this gives you available display size without the top bar.


I/System.out( 1900): width = 1004, height = 654

In this case I have additional elements on the top and side that limit the 1,280-by-800-pixel TFT display's drawing area.


As an Amazon Associate I earn from qualifying purchases.

No comments:

Post a Comment

Post Scriptum

The views in this article are mine and do not reflect those of my employer.
I am preparing to cancel the subscription to the e-mail newsletter that sends my articles.
Follow me on:
X.com (Twitter)
LinkedIn
Google Scholar

Popular Recent Posts

Most Popular Articles

apt quotation..