我在xamarin跨平台上有一个主详细信息页面,但Android上的导航非常慢
而不是滑动以隐藏菜单,它只是闪烁而消失我怎样才能让它看起来更快?
我也试着https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/master-detail-page/的例子 但是它在android上以缓慢的方式继续下去
我有我的masterdetail页面xaml
这是“MASTER”菜单XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Injoy.MasterPage"
Padding="0,50,0,0"
Title="Menú"
BackgroundColor="#dcdb26">
<ContentPage.Content>
<RelativeLayout>
<Image Aspect="Fill" Source="fondoAmarilloI.png"/>
<StackLayout>
<StackLayout VerticalOptions="Start" >
<Image Source="unnamed.png" WidthRequest="100" HeightRequest="80"/>
</StackLayout>
<StackLayout VerticalOptions="Center" >
<Button x:Name="CalendarBtn" Text="Calendario" BackgroundColor="Transparent" TextColor="White" HorizontalOptions="CenterAndExpand"/>
<Button x:Name="ProfileBtn" Text="Perfil" BackgroundColor="Transparent" TextColor="White" HorizontalOptions="CenterAndExpand"/>
<Button x:Name="PlanBtn" Text="Arma Tu Plan" BackgroundColor="Transparent" TextColor="White" HorizontalOptions="CenterAndExpand"/>
<Button x:Name="PayBtn" Text="Pago" BackgroundColor="Transparent" TextColor="White" HorizontalOptions="CenterAndExpand"/>
<Button x:Name="LogoutBtn" Text="Cerrar Sesión" BackgroundColor="Transparent" TextColor="White" HorizontalOptions="CenterAndExpand"/>
<!--<ListView x:Name="listView" RowHeight="50" BackgroundColor="Transparent">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" VerticalOptions="Center">
<Label x:Name="hide" Text="{Binding Name}"/>
<Label Text=" " />
<Image Source="{Binding IconSource}" HeightRequest="30" WidthRequest="30" />
<StackLayout Orientation="Vertical">
<Label Text="{Binding Title}" TextColor="White" HorizontalOptions="Center" VerticalOptions="Center" FontAttributes="Bold" FontSize="24" />
</StackLayout>
<Image Source="{Binding IconSource2}" HeightRequest="20" WidthRequest="20" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>-->
</StackLayout>
</StackLayout>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
代码背后的两个按钮示例
private void PlanBtnClickEvent(object sender, EventArgs e)
{
this.mainPage.Detail = new NavigationPage(new AddPlan());
this.mainPage.IsPresented = false;
}
private void LogOutBtnClickEvent(object sender, EventArgs e)
{
this.mainPage.Detail = new NavigationPage(new LogOut());
this.mainPage.IsPresented = false;
}
答案 0 :(得分:3)
怎么样:
private async Task PlanBtnClickEvent(object sender, EventArgs e) { mainPage.IsPresented = false; await Task.Run(() => { Task.Delay(300).Wait(); Device.BeginInvokeOnMainThread(() => { mainPage.Detail = new NavigationPage(new AddPlan()); }); }); } private async Task LogOutBtnClickEvent(object sender, EventArgs e) { mainPage.IsPresented = false; await Task.Run(() => { Task.Delay(300).Wait(); Device.BeginInvokeOnMainThread(() => { mainPage.Detail = new NavigationPage(new LogOut()); }); }); }
答案 1 :(得分:0)
IsPresented
更改为false
时,动画开始,并且与popToRootAsync =>并发,导致在masterPage菜单关闭时动画滞后。解决方案是:首先,我们在当前页面之前添加一个新页面,然后将其弹出并处理Appearing
事件。
var root = Detail.Navigation.NavigationStack[0];
MasterPage.ListView.SelectedItem = null;
if (item.Page == root)
{
IsPresented = false;
}
else
{
Detail.Navigation.InsertPageBefore(INSERT_YOUR_NEW_PAGE_HERE, root);
Device.BeginInvokeOnMainThread(async () =>
{
await Detail.Navigation.PopToRootAsync(false);
});
if(null != item.Page)
item.Page.Appearing += CloseMenuEvent;
}
最后,当您捕获事件时,关闭菜单并释放处理程序(否则,如果您存储页面,它将被多次调用)
private void CloseMenuEvent(object o, EventArgs args)
{
IsPresented = false;
var stack = Detail.Navigation.NavigationStack;
if ( null != stack && stack.Count > 0 )
Detail.Navigation.NavigationStack[0].Appearing -= CloseMenuEvent;
}
如果希望动画快速播放,请存储页面(在代码中标记为INSERT_YOUR_NEW_PAGE_HERE
)。
UPD:这不能解决应用程序崩溃的问题,但是this post的作用很大。
将Dispose
重载方法添加到ListViewRenderer
后,崩溃停止了。
这与滚动列表视图和同时选择一个新页面有一些关联。