Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get screen size of device? [duplicate]

Tags:

android

I would like to get the height of a android screen and if the screen inst a certain height, how would i go about doing this?

like image 366
yoshi24 Avatar asked Jul 05 '11 21:07

yoshi24


People also ask

How do I find out what my screen size is?

The size of a desktop computer monitor is determined by physically measuring the screen. Using a measuring tape, start at the top-left corner and pull it diagonally to the bottom-right corner. Be sure to only measure the screen; do not include the bezel (the plastic edge) around the screen.

How can I get mobile screen width and height?

Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.

How do you find the width of a device?

You can get the device screen width via the screen. width property. Sometimes it's also useful to use window. innerWidth (not typically found on mobile devices) instead of screen width when dealing with desktop browsers where the window size is often less than the device screen size.


1 Answers

If you want the display dimensions in pixels you can use this code:

Display display = getWindowManager().getDefaultDisplay();  int width = display.getWidth(); int height = display.getHeight(); 

Then you can add condition that compares the height to satisfy your needs.

In inches:

DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels/dm.xdpi,2); double y = Math.pow(dm.heightPixels/dm.ydpi,2); double screenInches = Math.sqrt(x+y); Log.d("debug","Screen inches : " + screenInches); 
like image 58
evilone Avatar answered Oct 01 '22 22:10

evilone