Since this hit high in google search I thought I'd update it with how I
currently get screen width. I am not saying its the best way (maybe
though)... but Display.getWidth is deprecated so Philips code from 2008
should not be used. Cheers.


public void onActivityCreated(Bundle savedInstanceState) {


DisplayMetrics metrics = new DisplayMetrics();


mScreenWidth = getDps(metrics.widthPixels);

On Sunday, December 30, 2007 9:31:17 AM UTC-6, Ian wrote:
On Dec 30, 4:48 am, Philip wrote:

Is there any way to programmatically determine the screen resolution
of the device?
Yes, but be careful what you want. This code in your Activity:

public void onCreate(Bundle icicle) {
. . .
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
. . .

will get you the *physical* display resolution. This is *not* the
size of your application, due to the status bar, title bar, etc.

To get your application's window size, as far as I know you have to
wait for

View.onSizeChanged(int width, int height, int oldw, int oldh);

to be called; this is *after* you've already created your GUI. This
means that if you're doing your own layout, you'll have to adjust it
in View.onSizeChanged. You can see how I handled this in Scrambled

Look in the source for BoardView:


You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-developers @
postedJul 10, '12 at 7:39p
activeJul 10, '12 at 7:39p

1 user in discussion

Randall Mitchell: 1 post



site design / logo © 2022 Grokbase