DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int w = displaymetrics.widthPixels;
int h = displaymetrics.heightPixels;
I'm using a "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
Karl, you have to take the screen density into account. You will need to multiply each of those values by...
density = getResources().getDisplayMetrics().density;
int w = displaymetrics.widthPixels * density;
int h = displaymetrics.heightPixels * density;
That will give you the actual screen size
Needs a
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="10" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With