user666
user666

Reputation: 332

How to make a scale only change height of a view?

I know ScaleTo can create an animation of a view.

but it will change the height and width,Is there anyway to change it's height by an animation?

Upvotes: 1

Views: 248

Answers (1)

Lucas Zhang
Lucas Zhang

Reputation: 18861

You can call the method LayoutTo.

For example

in xaml

<StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
    <BoxView x:Name="box" WidthRequest="300" BackgroundColor="Red" HeightRequest="600"  />
    <Button Clicked="Button_Clicked"  Text="Click Me"/>
</StackLayout>

in Code Behind

private async void Button_Clicked(object sender, EventArgs e)
{
   await box.LayoutTo(new Rectangle(box.Bounds.X, box.Bounds.Y, box.Bounds.Width, 300), 500, Easing.CubicIn);
}

For more details about different animation you can check https://trailheadtechnology.com/xamarin-forms-fancy-animations/

Upvotes: 1

Related Questions