Android Forums

Go Back   Android Forums > Android Coders > Android Code Snippets
Connect with Facebook

Click Here To Register!
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-07-2009, 08:12 PM (1398 Views 0 Replies)

Default Calculate The Size Of The Screen

Rate Thread
posted by BedHead

Code snippet to get the size of the device's screen.

java Code:
  1. package de.android.screentest;
  2.  
  3. import de.android.screentest.R;
  4. import android.app.Activity;
  5. import android.os.Bundle;
  6. import android.widget.LinearLayout;
  7. import android.graphics.Color;
  8. import android.graphics.drawable.Drawable;
  9. import android.widget.TextView;
  10. import android.view.Display;
  11.  
  12. import android.view.WindowManager;
  13.  
  14. public class ScreenTest extends Activity
  15. {   
  16.      private LinearLayout main;
  17.      private TextView tv;
  18.      
  19.      Display display;
  20.      
  21.      String txt;
  22.      
  23.     @Override
  24.     public void onCreate(Bundle savedInstanceState)
  25.     {
  26.         super.onCreate(savedInstanceState);
  27.        
  28.         main = new LinearLayout(this);
  29.         main.setBackgroundColor(Color.BLACK);
  30.         main.setOrientation(LinearLayout.VERTICAL);
  31.        
  32.         tv = new TextView(this);
  33.         tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT));
  34.         tv.setText(getScreenProps());
  35.         main.addView(tv);
  36.        
  37.         setContentView(main);
  38.     }
  39.    
  40.     private String getScreenProps()
  41.     {
  42.      String s = "screen property: ";
  43.      
  44.      display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
  45.      
  46.      int height = display.getHeight();
  47.      int width = display.getWidth();
  48.      
  49.      s = s + width + " " + height;
  50.      
  51.      return s;
  52.     }
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
0 Replies - 1398 Views
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
G1 Font Size Producer Android Hardware 3 06-22-2009 03:49 PM
Font size dindenver Android Chat 3 01-08-2009 03:21 PM
Font size castratikron Introduce Yourself 0 12-18-2008 12:54 PM
Wallpaper size sazyanti Android Chat 1 11-25-2008 07:29 PM
Screen Protector for the touch screen? fritz269 Android Chat 6 11-10-2008 11:06 PM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone | Android Phone

All times are GMT. The time now is 05:44 AM.



SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.