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 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-developers @
categoriesandroid
postedJul 10, '12 at 7:39p
activeJul 10, '12 at 7:39p
posts1
users1
websiteandroid.com

1 user in discussion

Randall Mitchell: 1 post

People

Translate

site design / logo © 2022 Grokbase