I want to use animation in my android Application using Xamarin C#. animations like fade-in, zoom-in, move and ....
The animations are basically of three types as follows: Property Animation. View Animation. Drawable Animation.
On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.
A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.
first add a folder under "resources " folder name it "anim". then you can add your animation resources to it , Ex: for fade-in animation create a resource under anim folder and name it "fade_in.xml" and paste this code into it:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
then add a Textview in your mainlayout.xml and also a button
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txtMessage"
android:layout_marginBottom="35.3dp" />
and for button:
<Button
android:text="fade in"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/fadein" />
in "oncreate" method in you activity add this code :
Button fadein = FindViewById<Button>(Resource.Id.fadein);
fadein.Click += btn_Click;
then add this method to your activity:
void blink_Click(object sender, EventArgs e)
{
txtMessage = FindViewById<TextView>(Resource.Id.txtMessage);
Button b = sender as Button;
Animation anim = AnimationUtils.LoadAnimation(ApplicationContext,
Resource.Animation.fade_in);
txtMessage.StartAnimation(anim);
}
You can make a simple fade animation like this :
txtMessage.Alpha = 0.0f;
txtMessage.Animate().Alpha(1.0f).SetDuration(1000).Start();
You can also animate other properties such as ScaleX
, RotationX
, TranslationX
, etc ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With