Invalid pixel width?

DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int w = displaymetrics.widthPixels; int h = displaymetrics.heightPixels; 

I am using the "Nexus One"

W shoud be 480 and H shoud be 800 ...

But for me, W is 320, and H is 533 ...

What am I doing wrong?

  DisplayMetrics displayMetrics = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); float CAMERA_WIDTH = displayMetrics.widthPixels * getResources().getDisplayMetrics().density; ; float CAMERA_HEIGHT = displayMetrics.heightPixels * getResources().getDisplayMetrics().density; ; Log.v("" + CAMERA_WIDTH + "---" + CAMERA_HEIGHT); 

VERBOSE: 320.0 --- 533.0

+6
android pixel
source share
2 answers

Is required

  <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="10" /> 
+7
source share

Carl, you have to consider the density of the screen. You will need to multiply each of these values ​​by ...

 density = getResources().getDisplayMetrics().density; int w = displaymetrics.widthPixels * density; int h = displaymetrics.heightPixels * density; 

This will give you the actual screen size.

+3
source share

All Articles