Wednesday, September 25, 2013

Simple animation to your android project

In here I explain how to add a simple animation to your android project. At final you will be able to see simple flashing set of images at your login screen.

1. Create xml file named "flag.xml" under drawable folder

2. Add following code to your flag.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/flaganim"
  android:oneshot="false">
  <item android:drawable="@drawable/sliit" android:duration="4000" />
  <item android:drawable="@drawable/mlb" android:duration="4000" />
  <item android:drawable="@drawable/logo" android:duration="4000" />
  <item android:drawable="@drawable/metro" android:duration="4000" />
  <item android:drawable="@drawable/convacation" android:duration="4000" />
   <item android:drawable="@drawable/matara" android:duration="4000" />
</animation-list>

3. To your main activity add following code

  final ImageView splashImageView = (ImageView) findViewById(R.id.imageView2);
  splashImageView.setBackgroundResource(R.drawable.flag);
  final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
  
  splashImageView.post(new Runnable(){
  @Override
   public void run()
  {
  frameAnimation.start();              
  }          
  });

4. Run the project



That's All :)
Thank You

No comments:

Post a Comment

Blogger Widgets