我遵循原始的android API並使用monodroid寫一個非常簡單的CustomView來繪製一個矩形。一旦我進入應用程序,它會自動進行。雖然我用eclipse寫了一個純粹的android,但它工作正常。或者當我刪除drawRect方法代碼時,它也可以正常工作。有沒有人知道這個或我做錯了什麼?canvas.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 });
}
這是我在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);
}
}
非常感謝。 霍華德
我還在掙扎這個問題。我正在使用評估版,有沒有人在其他版本測試? – Howard 2011-04-13 09:13:12