Your experience on this site will be improved by allowing cookies
With parameters like start value, end value, size, time duration, rotation angle, etc., Tween Animation performs the desired animation on an object. Tween Animation in Android is provided by a class called Animation, to be applied to any type of object. In Android, various classes and interfaces are present in the android. animation package, for animation development. Animation in Android can be simply understood as the phenomenon of changing the object property and behavior at run time. To do animation in android, we can use various ways. To start and end the animation, the methods of the AnimationDrawable class are used. The time-based animation can also be used for animation in Android.
Example:
In the below example, we are demonstrating the usage of android animation.
activity_main.xml:
In the activity_main.xml file, we will add some TextView, ImageView, and Buttons from the palette.
MainActivity class:(File: MainActivity.java)
package com.example.radioapp; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void clockwise(View view){ ImageView image = (ImageView)findViewById(R.id.imageView); Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation); image.startAnimation(animation); } public void zoom(View view){ ImageView image = (ImageView)findViewById(R.id.imageView); Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.clockwise); image.startAnimation(animation1); } public void fade(View view){ ImageView image = (ImageView)findViewById(R.id.imageView); Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade); image.startAnimation(animation1); } public void blink(View view){ ImageView image = (ImageView)findViewById(R.id.imageView); Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink); image.startAnimation(animation1); } public void move(View view){ ImageView image = (ImageView)findViewById(R.id.imageView); Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move); image.startAnimation(animation1); } public void slide(View view){ ImageView image = (ImageView)findViewById(R.id.imageView); Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide); image.startAnimation(animation1); } } |
AndroidManifest:(File: AndroidManifest.xml)
MyAnimation.xml:
Inside the res/anim directory, we will create the myanimation.xml file. We will also require an image which should be placed inside the res/drawable directory.
Blink.xml:
Inside the res/anim directory, we will create the blink.xml file.
Clockwise.xml:
Inside the res/anim directory, we will create the blink.xml file.
Fade.xml:
Inside the res/anim directory, we will create the blink.xml file.
Move.xml:
Inside the res/anim directory, we will create the blink.xml file.
> |
Slide.xml:
Inside the res/anim directory, we will create the blink.xml file.
> |
0 comments