[Android] ViewHeight function needed

Monkey Forums/Monkey Bug Reports/[Android] ViewHeight function needed

Xaron(Posted 2014) [#1]
DeviceHeight returns always the physical screen size which is ok. But on newer Android devices we need the view size as well which can be less than the physical size because of the soft buttons bar at the bottom.

I've posted a possible solution here:
http://monkeycoder.co.nz/Community/posts.php?topic=7827


Gerry Quinn(Posted 2014) [#2]
I think DeviceHeight should reflect the available area, i.e. the view size. That's how it works on HTML and Flash where it gives the size of the window rather than the monitor, after all.


marksibly(Posted 2014) [#3]
Sample code?

The below code seems to work OK, DeviceHeight returns 1205 on my nexus 7 (or 736 in landscape mode), which sounds about right for 1280 x 800. Also, the android target code just returns _view.getheight() which I'm pretty sure will exclude home button etc height.

If you want to move game graphics above the ad, you should subtract Admob.AdViewHeight from your playfield height - this allows you to 'clear' the area behind the ad any way you want.

Import mojo

Class MyApp Extends App
	
	Method OnCreate()
	
		SetUpdateRate 60
	End
	
	Method OnRender()
	
		Cls 255,255,255
		
		SetColor 255,0,0
		
		DrawRect 1,1,DeviceWidth-2,DeviceHeight-2
		
		SetColor 255,255,255
		
		DrawText "DeviceWidth="+DeviceWidth+", DeviceHeight="+DeviceHeight,2,2

	End
	
End

Function Main()

	New MyApp
	
End