android frame by frame animation example

      Comments Off on android frame by frame animation example

android frame by frame animation example

android frame by frame animation example

android frame by frame animation example is a complete set of android tutorial on how to use frame by frame animation in android. Here I have created 3 images and added to the drawable folder and I would like to apply this animation to the background of my main activity in android. For Frame, by frame animation, you need to create one XML file into a drawable folder and you need to setup parameters. I recommend you to refer tween animation before you go for frame by frame animation. Let’s have a look at the code for android animation.

android app will be more lovable if you add few animation into it, Here is the complete tutorial on how to add animation into your android apps and make it attractive for the world. you are spending lots of time in android development then you must check out android tips and tricks to save your time.

Don’t forget to add 3 images into a drawable folder. slide1.png, slide2.png and slide3.png.

Questions Related with Android Frame by Frame Animation

  • Write an outline code to show frame by frame animation. Load 2 Bitmap
    resources and create AnimationDrawable. What is the purpose of setOneShot()
    method.
  • Explain animation supported by Android taking suitable example
  • Explain different types of Animation in Android.
  • Differentiate Frame-by-frame Animation and Tweened Animation
  • Explain the steps involved in frame by the frame animation.
  • Which methods should be used to load 2 Bitmap resources and to start the animation in the case of Frame-by-Frame Animation? Which method should be used to loop continuously for animation?
    • setOneShot to false or default is continuous.
  • What is Frame-by-Frame Animation? How is it different from Tweened Animation? Explain creating frame-by-frame animation taking a suitable example.
  • What is the purpose of setOneShot() and addFrame() method in Frame By Frame animation?
    • setOneShot() : If true, the animation will only run a single time and then stop.
    • addFrame() : Adds a frame to the animation
  • For what purpose animation interpolator is used? How can it be specified
    programmatically?
  • An interpolator means the rate of change of an animation (mostly it is used for the smooth curve). This allows the basic animation effects (alpha, scale, translate, rotate)

Location: res\drawable
File: myframebyframeanimation.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<animation-list xmlns:android=”http://schemas.android.com/apk/res/android” >
<item
android:drawable=”@drawable/slide1″
android:duration=”2000″ />

<item
android:drawable=”@drawable/slide2″
android:duration=”2000″ />

<item
android:drawable=”@drawable/slide3″
android:duration=”2000″ />
</animation-list>

Location : res\layout
File: main_activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
	android:background="#3f51b5"
	 android:id="@+id/mainView1"
    tools:context="andriod.frame.by.frame.animation.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:textColor="#e8eaf6"
        android:text="Frame by Frame Animation"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="21dp"
        android:textColor="#e8eaf6"
        android:text="By Adarsh Patel"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

Location : src\package
File: MainActivity.java

package android.frame.by.frame.animation;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		
		AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(R.drawable.myframebyframeanimation);
		
		View iv1 = (View) findViewById(R.id.mainView1);
		
		iv1.setBackgroundDrawable(ad);
		ad.start();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}

Output 1

android frame by frame animation example

Output 2

android frame by frame animation example

Output 3

android frame by frame animation example

Hope you have implemented Android Frame by Frame example, If you have faced any query you can contact me any time using contact us page. Did you know, I have written 21 Program Sets for Android Step by Step?

PS:
If you like my article, Please share with your friends on Facebook, WhatsApp, Twitter, etc. Thanks in Advance.