android frame by frame animation example part 2

      Comments Off on android frame by frame animation example part 2

go back to android frame by frame animation example part 1

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 thepurpose 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 frame animation.
  • Which methods should be used to load 2 Bitmap resources  and to start animation in case of Frame-by-Frame Animation? Which method should be used to loop continuously for animation?
    • setOneShot to false or default is contineous.
  • What is Frame-by-Frame Animation? How it is different from Tweened Animation? Explain creating frame-by-frame animation taking 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 it can be specified
    programmatically?
  • An interpolator means rate of change of an animation (mostly it is used for smooth curve). This allows the basic animation effects (alpha, scale, translate, rotate)

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

Download Complete Code

[sociallocker]Download[/sociallocker]