简体   繁体   中英

Animate AbsoluteLayout item in Xamarin forms

The slider starts of like this.

<Slider x:Name = "one" AbsoluteLayout.LayoutBounds="0.5, 0.9, 0.6, 0.1" AbsoluteLayout.LayoutFlags="All" />

I then want to animate it so it goes upwards and gets a bit wider so I then used this code snippet:

await one.LayoutTo(new Rectangle(0.5, 0.1, 0.8, 0.1), 1500, Easing.CubicInOut)

When that code runs then the slider completely disappears from the screen.

Any idea how one can animate items that is being positioned by a absolutelayout?

I can't clearly imagine what you expect as an effect, but I bet it's something like this:

var newBounds = new Rectangle(one.Bounds.X - 10, one.Bounds.Y -5, one.Bounds.Width + 20, one.Bounds.Height +10);
one.LayoutTo(newBounds, 1500, Easing.CubicInOut); 

That will looks like this:

动图

I added an increase and decreased effect just to clarify

public static async Task AnimateViewInAbsoluteLayout(View view, Rectangle rectAbsolute, Rectangle rectDest, uint time, Easing easing = null)
        { 
            await view.LayoutTo(rectDest, time, easing);
            AbsoluteLayout.SetLayoutBounds(view, rectAbsolute);
            AbsoluteLayout.SetLayoutFlags(view, AbsoluteLayoutFlags.All);
        }

usage:

AnimateViewInAbsoluteLayout(viewToMove, AbsoluteLayout.GetLayoutBounds(viewDest), viewDest.Bounds, 250, Easing.Linear);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM