Problem with Display.getDisplayHeight()

23 views
Skip to first unread message

vix...@gmail.com

unread,
Dec 22, 2015, 11:38:47 AM12/22/15
to CodenameOne Discussions
Hi everybody,

I have a problem with Display.getDisplayHeight(), returns in some cases 800 and 762 in the others, only on devices not in the simulator, I think that difference is the system bar height, but I don't know why this happens. I call  Display.getHeight() on beforeForm() method. Please some one tell me how to obtain the screen height without bar system height! 
I working on Samsung Galaxy S3 mini with Android 4.1.2 and Sony Xperia C4 with Android 5.0


Thanks in advanced

Diamond

unread,
Dec 22, 2015, 4:00:20 PM12/22/15
to CodenameOne Discussions, vix...@gmail.com
Hi,

Are those values returned on 2 separate devices?

If yes, then that's normal. Different devices have different height and width.

vix...@gmail.com

unread,
Dec 22, 2015, 5:01:49 PM12/22/15
to CodenameOne Discussions
Hi Diamond,

No, on each device returned each value with and without bar, for example:
Galaxy S3 mini returned 800 and 763,
Sony Xperia C4 returned 1776 and 1701.

For each device returned two diferents values



Diamond

unread,
Dec 22, 2015, 10:51:01 PM12/22/15
to CodenameOne Discussions, vix...@gmail.com
Hi,

That's seems like a bug, getDisplayHeight() should always return a constant value, regardless of having statusbar or not.

Shai might have an explanation for this.

Shai Almog

unread,
Dec 23, 2015, 12:15:17 AM12/23/15
to CodenameOne Discussions, vix...@gmail.com
Hi,
when are these two values returned and how?

Notice that the system can report any height it wants, if it changes the height it will invoke a sizeChanged event.

I'm guessing that you used the native Android ActionBar which occupies space out of the total height and relied on a value taken while it was shown and while it wasn't shown. I suggest using Form's getHeight() for most things.

vix...@gmail.com

unread,
Dec 23, 2015, 10:27:02 AM12/23/15
to CodenameOne Discussions, vix...@gmail.com
Hi Shai,

I always call the method Display.getDisplayHeight () when my application starts in beforeInitialForm (), the problem is when I close the application and open again on several occasions returns a value , and sometimes returns a different one.


Thanks in advanced

Shai Almog

unread,
Dec 23, 2015, 10:49:52 PM12/23/15
to CodenameOne Discussions, vix...@gmail.com
Hi
we have limited control over the native ActionBar. So your call is problematic as it assumes that a value that is changeable remains constant...

To avoid this specific behavior use the Toolbar API which I would generally recommend as the default.
I still don't understand why it matters that you get two different values? Why do you need the height?
Reply all
Reply to author
Forward
0 new messages