Android Forums

Go Back   Android Forums > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
Reply
 
LinkBack Thread Tools Display Modes
Old 04-07-2009, 03:12 PM   #1
Member
 
BedHead's Avatar
 
Join Date: Mar 2008
Posts: 57
Friends: 0
View BedHead's Profile   View BedHead's Photo Album   View BedHead's Blog   View Social Groups
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.     }
BedHead is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
Reply With Quote
Reply

Thread Tools
Display Modes



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


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

All times are GMT -6. The time now is 07:40 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2008 TalkAndroid.com. All rights reserved.