How to get the width and height of the screen at the checkpoint of Motorola, Android

I used followng ways to get the width and height of the screen. When I run my application in motorola, I got width = 320pixel and height = 533 pixels. But the size of the motorla mark is 480 x 854 pixels. How to get a height like 854 and a width of 480 cm. Http://www.gsmarena.com/motorola_milestone-3001.php

Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int heightOfScreen = metrics.heightPixels; int widthOfScreen = metrics.widthPixels; System.out.println("...w1..."+width+"...h1..."+height+"....w2...."+widthOfScreen+"...h2..."+heightOfScreen); 

Output w 1 = 320 ... h1 = 533 ... w2 = 320 ... h2 = 533

+4
source share
3 answers

I tried using the following approach. It worked for me.

 WindowManager windowManager = (WindowManager) activity.getApplicationContext().getSystemService(Context.WINDOW_SERVICE); int height = windowManager.getDefaultDisplay().getHeight(); int width = windowManager.getDefaultDisplay().getWidth(); 
0
source

I have not tried this, but from what you have tried so far, I bet it will work:

 DisplayMetrics metrics = getResources().getDisplayMetrics(); float width = metrics.widthPixels * metrics.xdpi; float height = metrics.heightPixels * metrics.ydpi; 

Edit : You can also try Display.getSize .

The second edit . My first solution is wrong, and the second solution is only API level 13+. However, I tried both of your methods and they worked correctly on “Huawei Ideos X5” (Android 2.2) and Nexus S (Android 2.3.4). It could just be a Motorola bug. Are there any official updates for your phone OS?

+2
source

Try to execute

 Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); Log.i(TAG, "Width " + display.getWidth() + "\t\t Height :" + display.getHeight()); 
-1
source

All Articles