0

All right, so I'm making a game for Android. For the menu screen, I want to have the logo floating in the background, from right to left and vice versa. That doesn't seem too much of an issue, but I want it to be at random heights, and not out of the screen, so I'll need the resolution. I found the following script in the answers to this question:

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int scrHeight = size.y;

Unfortunately, I get an error in line 3:

Multiple markers at this line
- Syntax error on token "size", VariableDeclaratorId expected after this token
- Syntax error on token(s), misplaced construct(s)

I don't know what's wrong (I basically ctrl+c,ctrl+v'd it), and I feel kind of reluctant to use getHeight() since it's deprecated...

And then one tiny extra question: getSize was implemented in SDK 13, right? Does that mean it doesn't work on phones released before SDK 13, or is that something I can ignore?

Thanks already!

Community
  • 1
  • 1
  • Look at the last comment on the accepted answer for the question you link to, that has a solution for pre and post API 13. – cjk Jul 13 '12 at 15:47

3 Answers3

0

If you're targeting devices less than API level 13, then you'll have to make do with getHeight(). Using getSize() won't compile in that case.

Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104
0

Try this :

Display display = ((WindowManager) mContext.getSystemService(
    Context.WINDOW_SERVICE)).getDefaultDisplay();

int srcWidth = display.getWidth();
int srcHeight = display.getHeight();
throrin19
  • 17,796
  • 4
  • 32
  • 52
0

Yes you're right, this method won't work on pre AP13. You have to use display.getWidth(); and display.getHeight(); before API13.

AMerle
  • 4,354
  • 1
  • 28
  • 43