Xamarin 表单 - Lottie 动画 - CarouselView

发布于 2025-01-15 08:45:50 字数 2566 浏览 2 评论 0原文

我正在使用最新版本的 Xamarin Forms 和 Lottie 包。 我正在尝试在轮播视图中绑定lottie 动画。问题是在我滚动所有幻灯片后洛蒂动画开始。 (如果我不滚动动画是空白的) 我的 carouselview xaml 是:

<CarouselView
            PositionChanged="TheCarousel_PositionChanged"
            x:Name="TheCarousel"
            AbsoluteLayout.LayoutBounds="0,0,1,1"
            AbsoluteLayout.LayoutFlags="All"
            IndicatorView="indicatorview">
            
            <CarouselView.ItemTemplate>
                <DataTemplate>
                        <AbsoluteLayout>
                            <StackLayout 
                            AbsoluteLayout.LayoutBounds=
                            "0.5,0.3,AutoSize,AutoSize"
                            AbsoluteLayout.LayoutFlags=
                            "PositionProportional"
                            HorizontalOptions="Center"
                            >

                                <forms:AnimationView
                                    x:Name="animationView"
                                    Animation="{Binding animazione}"
                                    AnimationSource="EmbeddedResource"
                                    CacheComposition="True"
                                    AutoPlay="{Binding autoplay}"
                                    RepeatMode="Infinite"
                                    VerticalOptions="FillAndExpand"
                                    HorizontalOptions="FillAndExpand" />

                                <Label
                                FontSize="Title"
                                HorizontalOptions="Center"
                                HorizontalTextAlignment="Center"
                                Text="{Binding testo}"
                                VerticalOptions="Center" />



                            </StackLayout>
                        </AbsoluteLayout>
                </DataTemplate>
            </CarouselView.ItemTemplate>
        </CarouselView>

我通过代码填充它:

TheCarousel.BatchBegin();
intro = new ObservableCollection<Intro>();
var intro1 = new Intro { color1 = Color.Red, color2 = Color.Red, testo = "Hello 1", animazione = "Assets.71216-delivery-guy.json", autoplay = true };
var intro2 = new Intro { color1 = Color.RosyBrown, color2 = Color.Red, testo = "Hello 2", animazione = "Assets.pagamento-carte.json", autoplay = true };
intro.Add(intro1);
intro.Add(intro2);
TheCarousel.ItemsSource = intro;
TheCarousel.BatchCommit();

为什么会发生这种情况?

I'm using the latest version of Xamarin Forms and Lottie package.
I'm trying to bind lottie animation in carouselview. The problem is lottie animation start after i have scrolled all the slides. (if i not scroll the animation is blank)
my carouselview xaml is:

<CarouselView
            PositionChanged="TheCarousel_PositionChanged"
            x:Name="TheCarousel"
            AbsoluteLayout.LayoutBounds="0,0,1,1"
            AbsoluteLayout.LayoutFlags="All"
            IndicatorView="indicatorview">
            
            <CarouselView.ItemTemplate>
                <DataTemplate>
                        <AbsoluteLayout>
                            <StackLayout 
                            AbsoluteLayout.LayoutBounds=
                            "0.5,0.3,AutoSize,AutoSize"
                            AbsoluteLayout.LayoutFlags=
                            "PositionProportional"
                            HorizontalOptions="Center"
                            >

                                <forms:AnimationView
                                    x:Name="animationView"
                                    Animation="{Binding animazione}"
                                    AnimationSource="EmbeddedResource"
                                    CacheComposition="True"
                                    AutoPlay="{Binding autoplay}"
                                    RepeatMode="Infinite"
                                    VerticalOptions="FillAndExpand"
                                    HorizontalOptions="FillAndExpand" />

                                <Label
                                FontSize="Title"
                                HorizontalOptions="Center"
                                HorizontalTextAlignment="Center"
                                Text="{Binding testo}"
                                VerticalOptions="Center" />



                            </StackLayout>
                        </AbsoluteLayout>
                </DataTemplate>
            </CarouselView.ItemTemplate>
        </CarouselView>

and i populate it via code:

TheCarousel.BatchBegin();
intro = new ObservableCollection<Intro>();
var intro1 = new Intro { color1 = Color.Red, color2 = Color.Red, testo = "Hello 1", animazione = "Assets.71216-delivery-guy.json", autoplay = true };
var intro2 = new Intro { color1 = Color.RosyBrown, color2 = Color.Red, testo = "Hello 2", animazione = "Assets.pagamento-carte.json", autoplay = true };
intro.Add(intro1);
intro.Add(intro2);
TheCarousel.ItemsSource = intro;
TheCarousel.BatchCommit();

Why this happen ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文