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.

    @Override

    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);

        DisplayMetrics metrics = new DisplayMetrics();

        
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

        mScreenWidth = getDps(metrics.widthPixels);

    }

On Sunday, December 30, 2007 9:31:17 AM UTC-6, Ian wrote:
>
> On Dec 30, 4:48 am, Philip <[email protected]> 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: 
>
>     @Override 
>     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 
> Net: 
>
>     http://code.google.com/p/netscramble/ 
>
> Look in the source for BoardView: 
>
>     
> http://netscramble.googlecode.com/svn/trunk/ScrambledNet/src/org/hermit/netscramble/BoardView.java
>  
>
> Ian 
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to