我正在从一个页面导航到另一页(Xamarin形式的Android设备),我在某些操作后向UI添加了一个地图,并且在将映射添加到UI时,我可以觉得UI是UI是闪烁一秒钟。我们如何在不影响应用程序的性能的情况下正确添加新视图
public Constructor(string _jobOrderId, JobOrder jobOrderDetails)
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
vm = new OrderAssignmentDetailsVM();
this.BindingContext = vm;
}
protected override void OnAppearing()
{
base.OnAppearing();
ClickEvent();
SetUiElements();
GoogleMapData();
SetMaptoUI();
List.ItemsSource = vm.OrderStatusList;
}
向UI添加地图
private void SetMaptoUI()
{
//add map to UI
mapHolder.Children.Add(map);
mapHolder.Children.Add(new Image() { Source = "redpin.png", HeightRequest = 50, WidthRequest = 33, Margin = Device.OnPlatform(new Thickness(0, 0, 0, 60), new Thickness(0, 0, 0, 25), 0),
VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center });
}
如何在不影响UI性能的情况下正确添加UI视图?
更改网格中的元素后,必须分配主视图:
Content = null; //now mapHolder is detached from your main view hierarchy
mapHolder.Children.Add(map);
mapHolder.Children.Add(new Image() { Source = "redpin.png", HeightRequest = 50, WidthRequest = 33, Margin = Device.OnPlatform(new Thickness(0, 0, 0, 60), new Thickness(0, 0, 0, 25), 0),
VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center });
Content = mapHolder;