[mono-android] DrawLine problem with Paint.StrokeWidth = 1
Jonathan Pryor
jpryor at novell.com
Thu Mar 17 14:37:03 EDT 2011
On Mar 17, 2011, at 7:43 AM, Morten Nilsen wrote:
> Narcís Calvet wrote:
>>> Jonathan Pryor wrote:
>>> I don't know why this would fail, though I imagine that Mono isn't the
>>> problem (porting the code to Java and seeing what Java does would narrow
>>> this down).
>>
>> A colleague did a similar test with Java for Android in Eclipse and worked
>> fine there.
The problem is AndroidManifest.xml. Seriously.
So, for testing, I ported this to Java. (See attached file [0].)
It works as you'd expect, while the C# code you provided does not, as you previously mentioned.
I noticed one odd difference, though: the Java version was "bigger" than the C# version. They use the exact same coordinates, yet when shown on the screen the Java version was significantly larger than the C# version.
Odd.
So I looked at my Java AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jprl.DrawOnCanvas"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DrawActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I deemed this "close enough" to the generated Mono for Android version...except for one element, automatically generated by mandroid.exe, and thus in the C# AndroidManifest.xml but not the Java one:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
When I added the above element to the Java AndroidManifest.xml, the result is twofold:
1. The Java app now renders lines which are the same size, on screen, as the C# code.
2. The Java app is ALSO missing the same lines.
I have no idea why adding a /manifest/uses-sdk element would so drastically change the behavior of the application, especially when the documentation for uses-sdk [1].
The "fix" for your C# code is to edit Properties\AndroidManifest.xml (and/or create one if necessary), and add the following XML fragment within the <manifest/> element:
<uses-sdk />
This prevents mandroid.exe from adding the android:minSdkVersion and android:targetSdkVersion attributes, thus generating an AndroidManifest.xml which is closer to the "original" Java, and an app which shows all the lines (as desired).
Another working solution is to use a SrokeWidth of 0 instead of 1, which also shows all 5 lines.
- Jon
[0]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DrawActivity.java
Type: application/octet-stream
Size: 1543 bytes
Desc: not available
Url : http://lists.ximian.com/mailman/private/monodroid/attachments/20110317/65ca10bb/attachment.obj
-------------- next part --------------
[1] http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
More information about the Monodroid
mailing list