tags:

views:

81

answers:

2

Is there a way to obtain the size of the notification bar and title bar in android? At the moment I obtain display width and height with:

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

After that I want to subtract the sizes of the bars so that I can stretch a video without loosing ratio. Currently I hide the bars because I can't see a better way.

A: 

hi i think that isn´t necessary and that will be automatically if you use a VideoView

VideoView vv = (VideoView) findViewById(R.id.MainVideo);                        
    MediaController mc=new MediaController(this);
    mc.setEnabled(true);
    mc.show(0);
    vv.setMediaController(mc); 
    vv.setVideoURI(Uri.parse(URLMedia));
    vv.requestFocus();
    vv.showContextMenu();
    vv.start();         
Jorgesys
I use SurfaceView instead of VideoView because I implemented different UI for the control elements (I needed a volume control and a switch-fullscreen-button). I dont use MediaController.
phantomas
+2  A: 

Maybe this is a helpful approach: Referring to the Icon Design Guidelines there are only three different heights for the status (notification) bar depending on the screen density:

  • 24px for LDPI
  • 32px for MDPI
  • 48px for HDPI

So if you retrieve the screen density of the device using densityDpi of DisplayMetrics you know which value to subtract

so it could look something like that:

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int myHeight = 0;

    switch (metrics.densityDpi) {
        case DisplayMetrics.DENSITY_HIGH:
            Log.i("display", "high");
            myHeight = display.getHeight() - 48;
            break;
        case DisplayMetrics.DENSITY_LOW:
            Log.i("display", "low");
            myHeight = display.getHeight() - 32;
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            Log.i("display", "medium/default");
            myHeight = display.getHeight() - 24;
            break;
        default:
            Log.i("display", "Unknown density");
Martin
This looks promising. I tried to implement it, but even though densityDpi is declared public in the javadoc, I can't access it in Eclipse... Using density instead does not seem to be an alternative, as the javadoc says: "This value does not exactly follow the real screen size "
phantomas
I'll just edit the answer to add a few lines of code...
Martin
Thanks! I didn't realize that metrics.densityDpi is not available in Android 1.5. Now I change my project to use 1.6 and it works! I just changed one more thing: I multiplied the values by 2, e.g. display.getHeight() - 48 * 2. By that I substract the height of the titlebar AND the notification bar. Hope this holds for other devices too. Just tested it on the Nexus.
phantomas
I think it should, because the specification says so - would be great if you could accept the answer by clicking the tick icon on the left :)
Martin