1

I know the way to get "screen size" using DisplayMetrics, but as note in the SDK Document:

The size returned by this method does not necessarily represent the actual raw size (native resolution) of the display. The returned size may be adjusted to exclude certain system decor elements that are always visible. It may also be scaled to provide compatibility with older applications that were originally designed for smaller displays.

Is there anyway to get the real screen size?

Mat
  • 202,337
  • 40
  • 393
  • 406
Luke Vo
  • 17,859
  • 21
  • 105
  • 181
  • possible duplicate of [How to get screen size of device?](http://stackoverflow.com/questions/6589101/how-to-get-screen-size-of-device), http://stackoverflow.com/questions/7527459/android-device-screen-size – nandeesh Sep 08 '12 at 08:48
  • @VinayWadhwa I'm having a situation that I need to declare an array of data which has the size equals with the maximum size the screen can express, and it can't be changed later. Therefore, in case you are using Kindle Fire or Galaxy, using `DisplayMetrics` while the docking bar is online will return wrong result. – Luke Vo Sep 08 '12 at 12:03

1 Answers1

1

It may not be an answer for your question, but it could be useful to know that if you need a View's dimension as your code is being executed when its layout has not been laid out yet (for example in onCreate() ) you can setup a ViewTreeObserver.OnGlobalLayoutListener with View.getViewTreeObserver().addOnGlobalLayoutListener() and put the relevant code that needs the view's dimension there. The listener's callback will be called when the layout will have been laid out.

For more details visit : ViewTreeObserver

But for general screen dimension we use DisplayMetrics itself though ignoring the SDK document note.

Arpit Garg
  • 8,476
  • 6
  • 34
  • 59