Carlos Rodrigez
Carlos Rodrigez

Reputation: 1455

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?

Upvotes: 3

Views: 1443

Answers (2)

Gabriele Gindro
Gabriele Gindro

Reputation: 1

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);

Upvotes: 0

Diego Rafael Souza
Diego Rafael Souza

Reputation: 5314

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:

Gif

I added an increase and decreased effect just to clarify

Upvotes: 3

Related Questions