2015-10-19 60 views
1

为什么没有任何东西被吸引到我的活动?我正在创建一个形状,然后将其添加到activity.cs文件中的视图中。这与我如何给它画一幅画吗?或者我需要使其无效?Xamarin.Android形状不绘制到活动

形状:

namespace Pong.Droid 
     { 
      public class PaddleDrawingAndroid : View 
      { 
       private readonly ShapeDrawable _shape; 

       public PaddleDrawingAndroid(Context context) : base(context) 
       { 
        var paint = new Paint(); 
        paint.SetARGB(255, 200, 255, 0); 
        paint.SetStyle(Paint.Style.Stroke); 
        paint.StrokeWidth = 4; 

        _shape = new ShapeDrawable(new OvalShape()); 
        _shape.Paint.Set(paint); 

        _shape.SetBounds(20, 20, 300, 200); 
       } 

       protected override void OnDraw(Canvas canvas) 
       { 
        _shape.Draw(canvas); 
       } 
      } 
     } 

的活动:

namespace Pong.Droid.Views 
{ 
    [Activity(Label = "!PONG!", ScreenOrientation = ScreenOrientation.Landscape)] 
    public class GamePlayView : MvxActivity 
    { 
     private GamePlayViewModelAndroid _vm; 

     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 
      SetContentView(Resource.Layout.GamePlayView); 

      _vm = new GamePlayViewModelAndroid(); 
      DataContext = _vm; 

      AddContentView(new PaddleDrawingAndroid(this), null); 
     } 
    } 
} 

布局:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:local="http://schemas.android.com/apk/res-auto" 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textSize="40dp" 
      local:MvxBind="Text TotalFramesBeenHad" /> 
    </LinearLayout> 

回答

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


     SetContentView(new PaddleDrawingAndroid(this))\\have you tried this? 

    }