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>