rbz
rbz

Reputation: 769

Unable to get the correct screen size using Services for Android

So i am trying to get the screen size of the Moto Droid on my application. on my Create, i am using the Service windowManager to get the default display.

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

When i set it i get width of 320 and height 570. that looks wrong, it should be 320x480. i want to place a 300x50 image on the bottom of the screen on any device (actually) so normally i would get the height of the screen and minus the image height so it places it on a view. but since i am getting 570 for some reason, i have to scroll down to see the image. why is it getting the wrong screen size and is there another more accurate way of getting the size. Thank you

Layout code goes as follows

   linearOut = new LinearLayout(this);
    linear = new LinearLayout(this);
    linear.setOrientation(LinearLayout.VERTICAL);


    scroll = new ScrollView(this);
    linearOut.addView(scroll);
    scroll.addView(linear);

            linear.addView(text);
    linear.addView(bbottom.getViewGroup());

    setContentView(linearOut);

Upvotes: 0

Views: 1582

Answers (2)

rbz
rbz

Reputation: 769

I think i got it. so the info above shows full screen viewable. so that does include the status bar. Is there a way to see the height of the status bar? i am not sure if all android devices have the same pixel height for the status bar.

Upvotes: 0

Jorgesys
Jorgesys

Reputation: 126445

try this::

Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth(); 
    int height = display.getHeight();

Upvotes: 1

Related Questions