0

I don't have a 480x800 device so I am using genymotion emulator instead. The specs for Nexus-S says 480x800 but when I get the size of the screen in the app it says 480x728? I was wondering if that's something that is happening on the actual device as well or it is just a bug in genymotion emulator?

@Override
public void onClick( View view )
{
    if ( view == null )
        return;

    View v1 = getActivity().findViewById( R.id.bg );
    Toast.makeText( getActivity(), "height:" + v1.getHeight() + " width:" + v1.getWidth(), Toast.LENGTH_SHORT ).show();
}

I have these in my style.xml

    <item name="android:windowFullscreen">true</item>
    <item name="android:windowNoTitle">true</item>

Here is the layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background" >
</RelativeLayout>
Saeid Farivar
  • 1,667
  • 24
  • 43

2 Answers2

0

This is showing the dimensions of the Activity view. The width is right because that view spans the full width of the display. The height, however, is not the full resolution height because it is the full height, minus the height of the status bar, minus the height of the action bar. If you want the true resolution of the display, use the following code for API level 13 and up:

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

If you want to support lower than API 13, you can use:

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth();  // deprecated
int height = display.getHeight();  // deprecated
Nathan Walters
  • 4,116
  • 4
  • 23
  • 37
0

The difference in actual height and your view height is a height of software buttons bar at the bottom of the screen (it is 48 dp).

The correct way to determine actual screen height depends on device API version and described here: How to get real screen height and width?

use the following snippet:

int screenWidth = 0;
int screenHeight = 0;
if (Build.VERSION.SDK_INT >= 11) {
    Point size = new Point();
    try {
        this.getWindowManager().getDefaultDisplay().getRealSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
    } catch (NoSuchMethodError e) {
        Log.i("error", "it can't work");
    }

} else {
    DisplayMetrics metrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    screenWidth = metrics.widthPixels;
    screenHeight = metrics.heightPixels;
}
Community
  • 1
  • 1
nemezis
  • 536
  • 1
  • 6
  • 21
  • So, how do I get rid of those software buttons? is it also there on the actual device? – Saeid Farivar Jan 05 '14 at 18:31
  • This is not applicable to the Nexus S as it has physical buttons. – Nathan Walters Jan 05 '14 at 18:46
  • Genymotion Nexus S emulator is not an actual device copy, it is just that OS image with some tweaks, and yes, it shows software menu buttons. Software buttons strip height is 48dp not 48px, for hdpi density it is 48 * 1.5 = 72 px. – nemezis Jan 06 '14 at 19:51
  • There is no way to hide these software buttons on non-rooted device – nemezis Jan 06 '14 at 20:01