【问题标题】:Lottie animation as loading indicator- Xamarin.formsLottie 动画作为加载指示器 - Xamarin.forms
【发布时间】:2020-01-25 05:44:03
【问题描述】:

我有一个 xamarin 表单应用程序,其中包含一个使用 microcharts 的饼图。图的数据是从 Web API 获得的。一切正常。每次图形从 Web API 加载数据时,都会有一些延迟。因此图形的出现也需要时间。我想要做的是在图表出现之前使用 Lottie 动画 作为加载指示器。动画显示但它会闪烁并加载图表。

我做了什么

我的 xaml

  <Grid>
         <forms1:AnimationView 
                x:Name="AnimationView"                
                Animation="graphloading.json"       
                AutoPlay="True"
                Margin="10"              
                BackgroundColor="Transparent"                           
                VerticalOptions="FillAndExpand"
                HorizontalOptions="FillAndExpand" />    

                        <forms:ChartView x:Name="Chart1" isVisible="False"
                        HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>                     
                    </Grid>

我的 Xaml.cs 文件

protected override async void OnAppearing()
    {              
        await LoadDynamicGraph();
    }

    private async Task LoadDynamicGraph()
    {
        await Task.Run(() =>
        {                                          
                    // Graph Loading API call code                          
                        if (GraphDataObj[0] != null)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {

                                AnimationView.IsPlaying = false;
                                AnimationView.IsVisible = false;
                                Chart1.IsVisible = true;                                
                                foreach (var item in GraphDataObj[0].DailyScore)
                                {
                                    FirstGraphData = new List<ChartEntry>
                                    {
                                      new ChartEntry(float.Parse(item.CompletedItems))
                                    {

                                        Label = "Completed",                                           
                                       // ValueLabel = item.CompletedItems,
                                        Color = SKColor.Parse("#c90484"),
                                        TextColor = SKColor.Parse("#FFFFFF"),
                                    },

                                      new ChartEntry(float.Parse(item.TotalOpenItems))
                                    {
                                        Label = "Total ",
                                       // ValueLabel = item.TotalOpenItems,
                                        Color = SKColor.Parse("#00a8f3"),
                                        TextColor = SKColor.Parse("#FFFFFF"),
                                    }
                                    };
                                }
                                Chart1.Chart = new PieChart()
                                {
                                    Entries = FirstGraphData,
                                    BackgroundColor = SKColor.Parse("#002F4F4F")
                                };

                            });
                        }

        });

    }

目前动画只是出现并消失。我想让它显示一些时间,然后加载图表。任何帮助表示赞赏。

【问题讨论】:

    标签: xamarin.forms


    【解决方案1】:

    设置这个

    AnimationView.IsPlaying = false;
    AnimationView.IsVisible = false;
    Chart1.IsVisible = true;
    

    在您的功能结束时。它仍然会很快。你可以尝试设置一次定时器。

          finish = true;
          Device.StartTimer(TimeSpan.FromSeconds(5), () =>
                {
                    If(finish){
                        finish = false;
                        return true;}
                    //there turn off your animation
                    return false;
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 2020-03-05
      • 2020-08-10
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多