canvas.DrawRect导致应用自动退出。

| 我遵循原始的android API,并使用monodroid编写一个非常简单的CustomView来绘制矩形。输入应用程序后,它会自动运行。虽然我用eclipse编写了一个纯android系统,但效果很好。或者,当我删除drawRect方法代码时,它也可以正常工作。有人知道这件事或我做错了什么吗? 这里附上应用程序代码: [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 OnDraw(Android.Graphics.Canvas canvas)
    {
        base.OnDraw(canvas);
        canvas.DrawRect(new Rect(10, 10, 100, 100), new Paint { Color = Color.Red });
    }
这是我在日食中使用的代码:
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);
}
} 非常感谢。 霍华德     
已邀请:
您需要检查android日志以查看错误是什么: http://mono-android.net/Documentation/Guides/Android_Debug_Log     

要回复问题请先登录注册