如何解决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,110,110),paint);
}
}
非常感谢。
霍华德
解决方法
您需要检查android日志以查看错误是什么:
http://mono-android.net/Documentation/Guides/Android_Debug_Log
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。