C# 将Xamarin.Forms StackLayout转换为Android视图
我正在尝试将Xamarin.Forms堆栈布局转换为Android本机视图类,以便在IWindowManager.AddView方法中使用它 转换代码为C# 将Xamarin.Forms StackLayout转换为Android视图,c#,android,xamarin.android,cross-platform,xamarin.forms,C#,Android,Xamarin.android,Cross Platform,Xamarin.forms,我正在尝试将Xamarin.Forms堆栈布局转换为Android本机视图类,以便在IWindowManager.AddView方法中使用它 转换代码为 static class ViewToAndroidViewConverter { public static Android.Views.View GetNativeView(this VisualElement view) { if (Platform.GetRenderer(view) == null)
static class ViewToAndroidViewConverter
{
public static Android.Views.View GetNativeView(this VisualElement view)
{
if (Platform.GetRenderer(view) == null)
Platform.SetRenderer(view, Platform.CreateRenderer(view));
var renderer = Platform.GetRenderer(view);
renderer.Tracker.UpdateLayout();
return renderer.ViewGroup;
}
}
这就是我试图转换的StackLayout
StackLayout testView = new StackLayout();
testView.Children.Add(new Label { Text = "Incoming call text" });
testView.Children.Add(new Label { Text = incomingNumber });
testView.BackgroundColor = Color.Green;
windowManager.AddView( testView.GetNativeView(),
new WindowManagerLayoutParams {
Title = "Call title sample",
Gravity = GravityFlags.Center,
Type = WindowManagerTypes.SystemAlert,
Height = 500,
Width = 1080
});
问题是显示了此测试视图,但没有标签内容(仅绿色实心矩形)。
有没有办法从堆栈布局创建一个包含完整内容的android本机视图