Display screen width and height in pixels

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Display screen width and height in pixels

Postby ben » Sat Jan 05, 2008 5:00 am

How do we get the size of the display screen in pixels on startup of an activity before any drawings are initiated? The android.util.DisplayMetrics gives always 0 for width and 0 for height. Your help is much appreciated.
Ben
ben
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Dec 13, 2007 3:23 am

Top

Postby ben » Sat Jan 05, 2008 5:26 am

The following will give the size of the entire display including the status bar above the activity window.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.util.DisplayMetrics
  2.  
  3.  
  4.  
  5. DisplayMetrics dm = new DisplayMetrics();
  6.  
  7. getWindowManager().getDefaultDisplay().getMetrics(dm);
  8.  
  9.  
  10.  
  11. int w = dm.widthPixels;
  12.  
  13. int h = dm.heightPixels;
  14.  
  15.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
Ben
ben
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Dec 13, 2007 3:23 am

Postby tum0rc0re » Sat Jan 05, 2008 6:56 am

thanx, buddy :)
JQ Soft web page:
[b][url=http://jqsoft.ru/]http://jqsoft.ru/[/url][/b]
My proffesional blog: [b][url=http://maximyudin.blogspot.com]http://maximyudin.blogspot.com[/url][/b]
Facebook: [b][url=http://www.facebook.com/maxim.yudin]http://www.facebook.com/maxim.yudin[/url][/b]
User avatar
tum0rc0re
Senior Developer
Senior Developer
 
Posts: 158
Joined: Sun Nov 25, 2007 7:15 am
Location: Moscow, Russia

Top

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest