[mono-android] DrawLine problem with Paint.StrokeWidth = 1

Narcís Calvet narcis at steema.com
Fri Mar 18 10:45:44 EDT 2011


Hi Jon,

-----Original Message-----
From: monodroid-bounces at lists.ximian.com
[mailto:monodroid-bounces at lists.ximian.com] On Behalf Of Jonathan Pryor
Sent: dijous, 17 / març / 2011 19:37
To: monodroid at lists.ximian.com
Subject: Re: [mono-android] DrawLine problem with Paint.StrokeWidth = 1

>It works as you'd expect, while the C# code you provided does not, as you
previously mentioned.

Great, thanks for investigating this issue.


>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.

So this would indicate this is a general Android problem, not a Monodroid
problem.


>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 />

Yes, this worked fine but I don't think it's a good solution for us. I had
to modify the manifest in the demo project which uses the component we are
developing and which suffers from this problem. This means most users would
think our component is buggy and we should have to explain that to those
which give it a second chance. Moreover, I'm afraid this is a more complex
problem. I did some changes in the OnDraw method in the example I sent
yesterday:

    protected override void OnDraw(Canvas canvas)
    {
      base.OnDraw(canvas);

      Paint pen = new Paint();
      pen.Color = Color.Red;
      pen.StrokeWidth = 1;
      pen.SetStyle(Paint.Style.Stroke);

      Display disp =
this.Context.GetSystemService(Android.Content.Context.WindowService).JavaCas
t<Android.Views.IWindowManager>().DefaultDisplay;

      for (int x = 10; x < disp.Width; x=x+10)
      {
        canvas.DrawLine(x, 0, x, disp.Height, pen);
      }

      for (int y = 10; y < disp.Height; y=y+10)
      {
        canvas.DrawLine(0, y, disp.Width, y, pen);
      }      
    }

Some screenshots are available at http://bit.ly/hqXjEe. You'll see the
output is substantially different using the default manifest
(TestAppDefaultManifest.png) or modifying it (TestAppModifiedManifest.png):
1. The second image draws thicker lines.
2. The second image draws less lines than the first image and than it
should. I think the number of lines is correct in the first image.

This is even worse in the charting component we are developping for
Monodroid. See FastLineDefaultManifest.png and FastLineModifiedManifest.png.
In the first image you'll notice one segment in the line series is not
painted, text in the legend is slightly overlapping and close to do so in
the left axis. In the second image you'll see series segments are plotted
correctly and text plots much better but some axes grid lines are thicker
than others.

Having seen that, how do you think we should proceed? If it is the case that
this is an Android issue perhaps it should be reported directly to Android's
developers. Do you know which channel should be used for that purpose?


>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).

Would it be possible for mandroid.exe to not generate those attributes by
default?


>Another working solution is to use a SrokeWidth of 0 instead of 1, which
also shows all 5 lines.

Considering Steema Software shares the same .NET code base for different
assemblies I don't think this would be a very good solution either but
probably the only one we have for now.


Thanks in advance.


Best Regards,
 
Narcís Calvet
Steema Software
http://www.steema.com  
http://twitter.com/SteemaSoftware   
https://www.facebook.com/SteemaSoftware 





More information about the Monodroid mailing list