Xamarin动画从设备的左到中心

问题描述 投票:0回答:1

我正在尝试使用xamarin开发android应用。我需要动画,例如图像在第一次加载应用程序时从屏幕的左侧移动到主页的屏幕中央。我尝试了现有的动画技术,但并不满意,因为它始终允许从当前位置移动到下一个位置,然后再返回。但是我需要从左移到当前位置(在中心)或从右移到中心的当前位置的动画。有人可以帮忙解决一下。

await lookupsFrame.TranslateTo(100, 0, 700, Easing.SpringOut);

await lookupsFrame.TranslateTo(0, 0);

android xamarin
1个回答
0
投票

有许多解决方案可以实现。

例如,您可以使用AbsoluteLayout并更改框的位置

<AbsoluteLayout BackgroundColor="White" AbsoluteLayout.LayoutBounds="0,1,1,1">
    <!--  -->
    <Frame x:Name="lookupsFrame" BackgroundColor="Olive" AbsoluteLayout.LayoutBounds="0.00,0.5,0.2,0.2" AbsoluteLayout.LayoutFlags="All">

          //...

    </Frame>


</AbsoluteLayout>

private async void Button_Clicked(object sender, EventArgs e)
    {
        Device.BeginInvokeOnMainThread(async () =>
        {


            var xPosition = 0.5;
            var currentPosition = 0.0;
            while (currentPosition < xPosition)
            {
                await Task.Delay(1);
                currentPosition += 0.04;

                AbsoluteLayout.SetLayoutBounds(lookupsFrame, new Rectangle(currentPosition, 0.5, 0.2,0.2));
            }

        });
    }
© www.soinside.com 2019 - 2024. All rights reserved.