How can I get the width of the Screen

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How can I get the width of the Screen

Postby thedeftone » Sun Jun 01, 2008 1:16 pm

Hi

To create a dynamic layout I need to know the width and/or the height of the screen.
Is there any system variable or sth?

I tried the following:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         AbsoluteLayout absLayoutMain = new AbsoluteLayout(this);
  2.  
  3.  
  4.  
  5.         mDebug = new TextView(this);
  6.  
  7.         String s = Integer.toString(absLayoutMain.getHeight());  //get the height from the super View      
  8.  
  9.         mDebug.setText(s);
  10.  
  11.  
  12.  
  13.         absLayoutMain.addView(mDebug,
  14.  
  15.                         new AbsoluteLayout.LayoutParams(100, 100, 50, 50));        
  16.  
  17.        
  18.  
  19.         setContentView(absLayoutMain)
  20.  
  21.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But it keeps me telling the Views height is "0".

Any ideas how to work this out?

greets
thedeftone
Junior Developer
Junior Developer
 
Posts: 14
Joined: Wed Apr 09, 2008 7:51 pm

Top

Postby thedeftone » Mon Jun 02, 2008 3:38 pm

Soooo...I found a way to get the display's height/width:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         WindowManager a = this.getWindowManager();
  2.  
  3.         Display v = a.getDefaultDisplay();
  4.  
  5.         String s = "Height: " + v.getHeight();
  6.  
  7.         String b = "Widtht: " + v.getWidth();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


You may use this in a FAQ or sth :D
thedeftone
Junior Developer
Junior Developer
 
Posts: 14
Joined: Wed Apr 09, 2008 7:51 pm

Postby beausejour » Mon Jun 02, 2008 4:50 pm

Thank you for sharing your solution
beausejour
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Apr 15, 2008 4:04 pm
Location: France

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests