I have a screen size of 600 (width) x 1024 (height). I get the current width of 600, but get the height of 976 incorrectly (without turning the screen). I get the current width of 1024, but get the height of 552 incorrectly (with the screen rotated).
int rowPixelWidth = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
int rowWidth = (int)Math.floor(rowPixelWidth / this.getResources().getDisplayMetrics().density);
int rowPixelheight = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
int rowheight = (int)Math.floor(rowPixelheight / this.getResources().getDisplayMetrics().density);
Log.d("rowWidth","rowWidth"+rowWidth);
Log.d("rowheight","rowheight"+rowheight);
-------------------------------------------------------------
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="8" />
<supports-screens android:anyDensity="true"/>
-------------------------------------------------------------
What is wrong with this code?
Here are a few numbers for a typical screen width:
- 320dp: regular phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc.).
- 480dp: Tweener tablet such as Streak (480x800 mdpi).
- 600dp: 7-inch tablet (600x1024 mdpi).
- 720dp: 10-inch tablet (720x1280 mdpi, 800x1280 mdpi, etc.).
I get the current width but not get the current height for the whole device (without (screen 320x480).
I try the code from Get screen sizes in pixels , but this causes a problem.