将项目从 Xamarin.Android 转移到 Xamarin.Forms

Transfer project from Xamarin.Android to Xamarin.Forms

我在 Xamarin.Android 上有项目。 在 MainActivity.cs:

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

    LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.MyLinearLayout);
    Android.Widget.RelativeLayout rl = new Android.Widget.RelativeLayout(this);
    ...
    mainLayout.AddView (rl);
 }

我可以在 MainPage 上仅在 Xamarin.Forms 中添加 Android.Widget.RelativeLayout 吗?

您可以混合原生 Android/iOS/Windows 和 Xamarin.Forms。以下是相关示例:

https://github.com/xamarin/xamarin-forms-samples/tree/master/Forms2Native https://github.com/xamarin/xamarin-forms-samples/tree/master/Native2Forms

如果您只想在 MainPage 上使用本机 Android 视图,您可以为 MainPage (http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/) 创建一个自定义渲染器,并在渲染器中添加您的 Android 视图。