4

I'm currently developping my app to be compatible with the samsung multi window feature introduced with the galaxy note 2 and soon the galaxy s3. If you don't know what I'm talking about :
(source: androidheadlines.com)

If you are interested, here is a link to know how to do it : here

My problem is that I need to know the height/width that my app uses. I'm doing this :

displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
heightScreen = displaymetrics.heightPixels;
widthScreen = displaymetrics.widthPixels;

But this returns the size of the entire screen, not just the part that my app uses. My activity is only compose by a Panel which take the entire space, but the panel.getHeight() or getWidth() return 0.

How can I get the real height/width ?

Thanks in advance.

Community
  • 1
  • 1
Stephane Mathis
  • 6,542
  • 6
  • 43
  • 69

1 Answers1

6

My activity is only compose by a Panel which take the entire space, but the panel.getHeight() or getWidth() return 0.

Try checking later. You are probably checking for this in onCreate(), which is too soon AFAIK.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yeah, you were right. I now do it in the onDraw method and it's cool. When the user resize the window I can be aware of. – Stephane Mathis Nov 18 '12 at 20:03
  • Stephane - can you show us exactly how your solution looks at the end please? – Paul Hunnisett Dec 22 '12 at 12:06
  • The widgets are not actually 'drawn' and capable of reporting their sizes until the method `public void onWindowFocusChanged (boolean hasFocus)` is called. You can override it and get metrics there as well (for future googlers looking for a solution). – spartygw Apr 23 '14 at 18:04
  • I wonder if this going to be the way of doing things on Android N, or will Android get methods that tell us the window size at onCreate time. – Justin Mar 29 '16 at 17:51
  • @StephaneMathis What is the final solution please? – Krish Jun 28 '16 at 07:14