Change canvas size
Monkey Targets Forums/Android/Change canvas size
| ||
To change the size of the display... In .build\android\templates\res\layout\main.xml, change this android:layout_width="fill_parent" android:layout_height="fill_parent" Into this (set your size+px) android:layout_width="320px" android:layout_height="240px" Then save. (Delete any .bak files, as this might cause a compile error) |
| ||
The whole point of using fill_parent is so that the canvas matches your screen. As soon as you put a hardcoded size on the canvas, you're developing for a specific group of handsets and excluding users with different screen sizes. If you're going to be developing for a platform that has multiple screen sizes, you should be running in native res and scale your UI to match. |
| ||
Yes I realize this. But at the same time I would also prefer to use the native resolution of the device. My phone is capable of an native resolution of 800x480. But monkey initializes automatically a canvas resolution of only 533x320. I have no problem with "fill_parent", but imo there should be an option to set the canvas size equal to the native resolution the device offers. The reason I want to use native resolution is the clear and crisp graphics/text rendering. I realize this is not what my code offers above. It acts more like a viewport size. So if someone knows how to set the native resolution, please share! :) |
| ||
Add this to your manifest;<supports-screens android:resizeable="false" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" /> |
| ||
ah thanks! But it didnt do much. Care to give a brief description on what that snippet is supposed to do? |
| ||
Hum works for me and my 480x800 HTC Desire. Here is my whole manifest; And just to be sure make sure your editing the template/manifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="${APP_PACKAGE}" android:versionCode="1" android:versionName="1.0"> <supports-screens android:resizeable="false" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" /> <application android:label="${APP_LABEL}" android:icon="@drawable/icon"> <activity android:name="MonkeyGame" android:label="${APP_LABEL}" android:screenOrientation="${SCREEN_ORIENTATION}" android:configChanges="keyboardHidden|orientation" android:theme=\"@...; <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> |
| ||
Thanks supertino! It works! :) |
| ||
I hope I am not being daft, but where is the template/manifest.xml located? Under my android build (using the clock demo by difference)I see MonkeyPro/bananas/difference/clock/clockandy.build/android/templates/AndroidManifest.xml and alternatively I see MonkeyPro/targets/android/templates/AndroidManifest.xml Search as I may, no template/manifest.xml I have successfully compiled and put the clock demo on my Captivate. The screen display is sized wrong compared to the HTML version. Hoping Supertino's manifest would fix that, but I am lost at this point. My first hurdle. |
| ||
@ Loofadawg it is found in the first place you mention. For example.Import mojo.app Import mojo.graphics Function Main() New HelloWorld End Class HelloWorld Extends App Method OnRender() Cls DrawText "Hello World",10,10 End Method End Save the above source code in a folder called "hello" and call the file "helloworld.monkey". Run it as HTML5 (to check it works). Now run it as Android. You'll now see additional folders in your /hello folder, go to the /android folder, There are two files that can be edited; /templates/AndroidManifest.xml /CONFIG.TXT Hope this helps. |
| ||
Thank you Supertino for helping. I did what you said and I can clearly see which files to edit. Hurdle #2 I went back to the clock demo and started a fresh build for Android and named it clock2.monkey. Tested it on my device and it runs fine except that the app's shows only the left hand portion of the clock and in landscape mode shows the top portion. I replaced the AndroidManifest.xml with yours and now it won't compile. Translating clock2 C:/Users/Frank/Desktop/Monkey/MonkeyPro/bin/trans_winnt -config=release -target=android C:/Users/Frank/Desktop/Monkey/MonkeyPro/bananas/difference/clock/clock2.monkey TRANS monkey compiler V1.04 Parsing... Semanting... Translating... Building... Buildfile: C:\Users\Frank\Desktop\Monkey\MonkeyPro\bananas\difference\clock\clock2.build\android\build.xml [setup] Android SDK Tools Revision 10 [setup] Project Target: Android 2.1-update1 [setup] API level: 7 [setup] [setup] ------------------ [setup] Resolving library dependencies: [setup] No library dependencies. [setup] [setup] ------------------ [setup] [setup] [Fatal Error] :17:18: Open quote is expected for attribute "{1}" associated with an element type "android:theme". BUILD FAILED C:\Users\Frank\Desktop\Monkey\MonkeyPro\bananas\difference\clock\clock2.build\android\build.xml:65: org.xml.sax.SAXParseException: Open quote is expected for attribute "{1}" associated with an element type "android:theme". at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:468) at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:515) at com.android.ant.SetupTask.checkManifest(SetupTask.java:307) at com.android.ant.SetupTask.execute(SetupTask.java:193) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:390) at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:180) at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:82) at org.apache.tools.ant.Main.runBuild(Main.java:793) at org.apache.tools.ant.Main.startAnt(Main.java:217) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) --------------- linked to ------------------ javax.xml.xpath.XPathExpressionException at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:473) at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:515) at com.android.ant.SetupTask.checkManifest(SetupTask.java:307) at com.android.ant.SetupTask.execute(SetupTask.java:193) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:390) at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:180) at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:82) at org.apache.tools.ant.Main.runBuild(Main.java:793) at org.apache.tools.ant.Main.startAnt(Main.java:217) at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280) at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109) Caused by: org.xml.sax.SAXParseException: Open quote is expected for attribute "{1}" associated with an element type "android:theme". at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:468) ... 17 more Total time: 0 seconds * server not running * Android build failed. Process Complete |
| ||
I deleted the / after android:theme and tried to compile again and i get this:[setup] [Fatal Error] :2:6: The processing instruction target matching "[xX][mM][lL]" is not allowed. Care to do a build of the clock demo for android, zip it in an archive build folder et al? I am stumped. Blitz and Blitz3D I can do, but this? I feel green again. |
| ||
Okay, I think I see the problem... it is with all the sections that include ${blah-blah}. I need a tutorial on this. :^P |
| ||
Success!! So, my new manifest looks like this: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.monkey" android:versionCode="1" android:versionName="1.0"> <supports-screens android:resizeable="false" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" /> <application android:label="Monkey Game" android:icon="@drawable/icon"> <activity android:name="MonkeyGame" android:label="Monkey Game" android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation" android:theme=\"@...;; <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> The clock fits the screen... I feel so empowered now. Big thanks. Now to try a little coding to get my feet wet. So excited!! |
| ||
How can I stretch the content to the full screen? I develop for a resolution of 480x320 (standard iPhone 3 resolution 3:2) which doesn't fit completely into my 800x480 desire screen size (which is a strange 5:3 format). There is a black gap on the right side in landscape mode. I guess it's because the screen is resized proportional. That's ok but is there a way to center this at least? |
| ||
How can I stretch the content to the full screen? I develop for a resolution of 480x320 (standard iPhone 3 resolution 3:2) which doesn't fit completely into my 800x480 desire screen size (which is a strange 5:3 format). There is a black gap on the right side in landscape mode. I guess it's because the screen is resized proportional. That's ok but is there a way to center this at least? Yeah, be big, scale down.... I've learnt iOS iOS3 sizes are pretty poor, go for their big 4.x res and work down over, this should ensure you can fit your guff on Android! Or, try changing this: android:anyDensity="true" to android:anyDensity="false" Might work, dunno? Dabz |
| ||
Thanks Dabz, unfortunately that didn't change anything.![]() I'd be glad to have it centered instead of having that black border on the right site. Is that possible? edit: Here a screeny from a Wildfire: ![]() Same problem but now the menu on the right site is missing. Uh oh these aspect ratios are driving me crazy! So my Desire HD has 800x480 which is a ratio of 1.667 The Wildfire has 320x240 which is a ratio of 1.333 And then we have the iPhone which has 480x320 (or double) which is a ratio of 1.500 |
| ||
I wouldnt worry too much about the Wildfire and phones with the 320x240 resolution. |
| ||
You're probably right, yes. I even didn't know that there are Androids with 320x240 resolution until I saw the one my colleague has. But after all it would be nice to have it at least centered if possible. |
| ||
How are you scaling the display? Im doing the following: Const WIDTH# = 480 Const HEIGHT# = 320 Global SCALE_RATIO_X# Global SCALE_RATIO_Y# ... Method OnCreate() SCALE_RATIO_X = DeviceWidth()/WIDTH SCALE_RATIO_Y = DeviceHeight()/HEIGHT End Method OnRender() PushMatrix Scale SCALE_RATIO_X, SCALE_RATIO_Y PopMatrix End |
| ||
Ah thanks for that. At the moment I don't scale anything just let the device doing this. Will try it! edit: Yay! That works. Thanks! |