开发者

canvas.DrawRect causes app auto quit

I follow the original android API and use the monodroid to write a very simple CustomView to draw a rectangle. Once I enter the application, it automatically quites. While I write a pure android with eclipse, it works fine. Or when I delete the drawRect method code, it works fine too. Does anyone know this or something wrong I did?

Here attaches the apps code:

[Activity1.cs]

int count = 1;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button>(Resource.Id.MyButton);
        LinearLayout layoutRoot = FindViewById<LinearLayout>(Resource.Id.LayoutRoot);
        layoutRoot.AddView(new DrawableView(this));

        button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
    }

[DrawableView.cs]

protected override void On开发者_JAVA百科Draw(Android.Graphics.Canvas canvas)
    {
        base.OnDraw(canvas);
        canvas.DrawRect(new Rect(10, 10, 100, 100), new Paint { Color = Color.Red });
    }

this is the code I use in the eclipse:

public class DrawableView extends View {

public DrawableView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    Paint paint = new Paint();
    paint.setColor(Color.RED);
    canvas.drawRect(new Rect(10, 10, 110, 110), paint);
}

}

Thanks a lot. Howard


You need to check the android log to see what the error is:

http://mono-android.net/Documentation/Guides/Android_Debug_Log

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜