Sushan Ghimire
Sushan Ghimire

Reputation: 7567

Whats the appropriate way to work with phone screen size?

The following code returns the screen size:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();
int height = display.getHeight();

I'm using RelativeLayout to arrange components inside. For some reason when I divide width between components (say width*30/100 and width*70/100) I get some screen space left out. And also about the height how can I get height of status bar and title bar does it vary among phones?

Upvotes: 1

Views: 113

Answers (2)

josephus
josephus

Reputation: 8304

Answer is all in here

Quick summary: Android rounds up/down these values based on the nearest supported density/size ratio. You may not get the exact measurements you want, depending on your phone.

Also, Display is deprecated - use DisplayMetrics

Upvotes: 1

Seshu Vinay
Seshu Vinay

Reputation: 13588

this would help you. It states the difference in the sizes of status bar.

Upvotes: 1

Related Questions