Xamarin.Forms Animation
Hello friends! Animation is a great way to help you make your app even more attractive and smooth. Note that there is no XAML interface for the Xamarin.Forms animation classes. However, animations can be encapsulated in behaviors and then referenced from XAML.
The ViewExtensions class provides the following extension methods that can be used to create simple animations.
- TranslateTo animates the TranslationX and TranslationY properties of a VisualElement.
- ScaleTo animates the Scale property of a VisualElement.
- RotateTo animates the Rotation property of a VisualElement.
- RotateXTo animates the RotationX property of a VisualElement.
- RotateYTo animates the RotationY property of a VisualElement.
- FadeTo animates the Opacity property of a VisualElement.
Each
extension method in the ViewExtensions implements a single animation
operation that progressively changes a property from one value to
another value over a period of time.
Scaling
The scale method increases or decreases the size of an element (according to the parameters given for the width and height). Scaling refers to the resizing of an element. Scaling is used to change the visual appearance of an image, to alter the quantity of information stored in a scene representation, or as a low-level preprocessor in multi-stage image processing chain which operates on features of a particular scale.
Rotation
A rotation is a circular movement of an object around a center (or point) of rotation. The rotate method rotates an element clockwise or counter-clockwise according to a given degree.
Translation
The translate method moves an element from its current position (according to the parameters given for the X-axis or TranslationX and the Y-axis or TranslationY).
Fading
There is no property such as transparency. But, you can achieve transparency by inserting a pseudo element with regular opacity the exact size of the element behind it. The opacity-level describes the transparency-level, it ranges from 0.0 to 1.0. The level 0.0 is completely transparent, 0.5 is 50% see-through and level 1.0 is not transparent. Opacity has a default initial value of 1 (100% opaque).
The opacity property specifies the opacity/transparency of an element. The opacity property can take a value between 0.0 - 1.0.
Scaling
The scale method increases or decreases the size of an element (according to the parameters given for the width and height). Scaling refers to the resizing of an element. Scaling is used to change the visual appearance of an image, to alter the quantity of information stored in a scene representation, or as a low-level preprocessor in multi-stage image processing chain which operates on features of a particular scale.
- await image.ScaleTo (2, 2000);
A rotation is a circular movement of an object around a center (or point) of rotation. The rotate method rotates an element clockwise or counter-clockwise according to a given degree.
- await image.RotateTo (360, 2000);
The translate method moves an element from its current position (according to the parameters given for the X-axis or TranslationX and the Y-axis or TranslationY).
- await image.TranslateTo (-100, -100, 1000);
There is no property such as transparency. But, you can achieve transparency by inserting a pseudo element with regular opacity the exact size of the element behind it. The opacity-level describes the transparency-level, it ranges from 0.0 to 1.0. The level 0.0 is completely transparent, 0.5 is 50% see-through and level 1.0 is not transparent. Opacity has a default initial value of 1 (100% opaque).
The opacity property specifies the opacity/transparency of an element. The opacity property can take a value between 0.0 - 1.0.
- image.Opacity = 0; await image.FadeTo (1, 4000);
Compound Animations
A compound animation is a sequential combination of animations and can be created with the await operator.
Composite Animations
A composite animation is a combination of animations where two or more animations run simultaneously. Composite animations can be created by mixing awaited and non-awaited animations.
Canceling Animations
A compound animation is a sequential combination of animations and can be created with the await operator.
Composite Animations
A composite animation is a combination of animations where two or more animations run simultaneously. Composite animations can be created by mixing awaited and non-awaited animations.
- await Task.WhenAll(image.RotateTo(307 * 360, 2000), image.RotateXTo(251 * 360, 2000), image.RotateYTo(199 * 360, 2000));
An application can cancel one or more animations with a call to the static ViewExtensions.CancelAnimations method.
Let`s start Animation Demo.
Create an XAML and design:
- ViewExtensions.CancelAnimations (image);
Create an XAML and design:
- <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- x:Class="DemoApp.DemoAnimation"
- Title="Animation Demo">
- <ContentPage.Content>
- <StackLayout BackgroundColor="Gray" Padding="10" VerticalOptions="FillAndExpand">
- <StackLayout BackgroundColor="LawnGreen" Padding="10" VerticalOptions="Start" >
- <Image x:Name="Translaeimage" Source="icon" Aspect="AspectFit" HorizontalOptions="Center" VerticalOptions="Start"/>
- <Image x:Name="Scallimage" Source="icon" Aspect="AspectFit" HorizontalOptions="Center" VerticalOptions="Start"/>
- <Image x:Name="Fadimage" Source="icon" Aspect="AspectFit" HorizontalOptions="Center" VerticalOptions="Start"/>
- <Image x:Name="Rotateimage" Source="icon" Aspect="AspectFit" HorizontalOptions="Center" VerticalOptions="Start"/>
- <Image x:Name="CompImg" Source="icon" Aspect="AspectFit" HorizontalOptions="Center" VerticalOptions="Start"/>
- <ScrollView Orientation="Horizontal" VerticalOptions="End">
- <StackLayout VerticalOptions="End" Orientation="Horizontal">
- <Button Text="Fad" Clicked="Fad_Clicked"/>
- <Button Text="Scall" Clicked="Scall_Clicked"/>
- <Button Text="Rotate" Clicked="Rotate_Clicked"/>
- <Button Text="Trans." Clicked="Translate_Clicked"/>
- <Button Text="Compound" Clicked="Compound_Clicked"/>
- </StackLayout>
- </ScrollView>
- </StackLayout>
- </StackLayout>
- </ContentPage.Content>
Now, let us write the C# code:
- public partial class DemoAnimation : ContentPage
- {
- public DemoAnimation()
- {
- InitializeComponent();
- }
- private async void Fad_Clicked(object sender, EventArgs e)
- {
- Fadimage.Opacity = 0; //Opacity Change to 0 meanse element fully Hide
- await Fadimage.FadeTo(1, 2000); //Opacity Change to 1 meanse element fully Appear in 2 sec
- }
- private async void Scall_Clicked(object sender, EventArgs e)
- {
- await Scallimage.ScaleTo(2, 2000);// Resize the Element
- await Task.Delay(1000); //1 Sec interval time
- await Scallimage.ScaleTo(1, 2000);// Resize the Element
- }
- private async void Rotate_Clicked(object sender, EventArgs e)
- {
- await Rotateimage.RotateTo(360, 2000);//Element Rotate to 360 degree in 2 sec
- }
- private async void Translate_Clicked(object sender, EventArgs e)
- {
- await Translaeimage.TranslateTo(100, 100, 2000);// Move to down Element
- await Task.Delay(1000); //1 Sec interval time
- await Translaeimage.TranslateTo(0, 0, 2000); // Move to down Element
- }
- private async void Compound_Clicked(object sender, EventArgs e)
- {
- await CompImg.TranslateTo(0, 200, 2000, Easing.BounceIn);// Move to down Element
- await CompImg.ScaleTo(2, 2000, Easing.CubicIn); // Resize the Element
- await CompImg.FadeTo(0, 1000); //Opacity Change to 0 meanse element fully Hide
- await CompImg.FadeTo(1, 1000); //Opacity Change to 1 meanse element fully Appear
- await CompImg.RotateTo(360, 2000, Easing.SinInOut); //Element Rotate to 360 degree
- await CompImg.ScaleTo(1, 2000, Easing.CubicOut); //Again Resize the Element
- await CompImg.TranslateTo(0, 0, 2000, Easing.BounceOut); // Move to up the Element
- }
- }
Animation In Android
I think this is the best article today. Thanks for taking your own time to discuss this topic.
ReplyDeleteXamarin Training in Chennai
Xamarin Training
TOEFL Coaching in Chennai
French Classes in Chennai
pearson vue test center in chennai
Informatica Training in Chennai
Xamarin Training in Adyar
Xamarin Training in Velachery