Android Tutorial: Frame Animation With Multiple Images

In Android Animations are used in many ways like Splash screen or Layout animation between two activities , moving from one activity to the other you can see some moving animation. 
In Android Two kinds of animations available.
  • Tween animation :- Tween animation can perform a series of simple transformations like position, size, rotation, and transparency on widgets(Button,Text view etc).
  • Frame By Frame Animation :- it animate images in sequence. it means it show images in sequence like Gif file or Film.
In this tutorial I will show you how you can create Frame by Frame Animation to show images in sequence on splash screen. usually splash screen is not good in application (See developer review) but if you require some sort of back ground work when application starts you can use splash screen. Splash screen are known as evil because when you display it for longer time user get frustrated and may close your application or may remove it. but if you are creating game or application for some specific website then you can use splash screen to display logo of that website (Like Facebook app). lets start the new application for Frame by Frame Animation.
  • Create New Application. (Go to File > New >Android Application Project )

  • Now Click Next  > Next and Give Splash Activity name for java and splash.xml.
  • Now Go to splash.xml File and add Image view in it.
splash.xml



    


  • Now Go to SplashActivity.java and put the below code.
SplashAcivity.java

package com.androprogrammer.frameanimation;


import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.view.Menu;
import android.widget.ImageView;

public class SplashActivity extends Activity {

 ImageView iv1;
 AnimationDrawable Anim;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.splash);
  iv1 = (ImageView) findViewById(R.id.imageView1);
  try {
   BitmapDrawable frame1 = (BitmapDrawable) getResources().getDrawable(
     R.drawable.untitled1);
   BitmapDrawable frame2 = (BitmapDrawable) getResources().getDrawable(
     R.drawable.untitled2);
   BitmapDrawable frame3 = (BitmapDrawable) getResources().getDrawable(
     R.drawable.untitled3);

   Anim = new AnimationDrawable();
   Anim.addFrame(frame1, 200);
   Anim.addFrame(frame2, 200);
   Anim.addFrame(frame3, 200);
   Anim.setOneShot(false);
   iv1.setBackgroundDrawable(Anim);
   final Handler handler = new Handler();
   handler.postDelayed(new Runnable() {

    public void run() {
     
     Anim.start();
     
    }
   }, 5000);
   
  } catch (Exception e) {
   // TODO: handle exception
  }
  
  
 }
}

So This will start animating your images in sequence. in above code i have used handler that start new thread and call Start() method of Animation object. to display splash screen in full screen ( no action bar or application name in Api 11 or below ) you have to add the below code in manifest file. in activity tag add this code 
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Screen Shots



So this will allow to show splash images in full screen. i hope this will be helpful in your application.if you find helpful tutorial on this site subscribe to our blog or share it with your friends. 

2 comments :

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. thanks for your time .. will give it shot . i am falling in lve with andoid .. man android L is far beyond amazing

    ReplyDelete