Easy Way To Create Frame By Frame Animation Effect In Android Using BitmapDrawable Class In Android:
For Example:
Note: First Image That Will Dislay Blank When You Press Start Then Apper Imagies Effect And When
You Press StopAnimation Effect Then Stop Animation Effect:
1]Create Java File Then Put Code In MainActivity.java File:
package com.fremedemo;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class FrameActivity extends Activity {
AnimationDrawable manimation=new AnimationDrawable();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.button1);
Button btn2=(Button)findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView iv=(ImageView)findViewById(R.id.imageView1);
BitmapDrawable frame1=(BitmapDrawable)getResources().getDrawable(R.drawable.subh_navratri);
BitmapDrawable frame=(BitmapDrawable)getResources().getDrawable(R.drawable.index);
BitmapDrawable frame2=(BitmapDrawable)getResources().getDrawable(R.drawable.icon);
int resonableduration=250;
manimation.addFrame(frame1, resonableduration);
manimation.addFrame(frame, resonableduration);
manimation.addFrame(frame2, resonableduration);
iv.setBackgroundDrawable(manimation);
manimation.setOneShot(false);
manimation.start();
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
manimation.stop();
}
});
}
}
2] Create XML File In res/main.xml then put code this:
Note:Take Two Button And One Imageview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation Effect" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop Animation Effect" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="377dp"
android:layout_height="235dp"
android:layout_weight="0.89" >
</ImageView>
</LinearLayout>
For Example:
You Press StopAnimation Effect Then Stop Animation Effect:
1]Create Java File Then Put Code In MainActivity.java File:
package com.fremedemo;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class FrameActivity extends Activity {
AnimationDrawable manimation=new AnimationDrawable();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.button1);
Button btn2=(Button)findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ImageView iv=(ImageView)findViewById(R.id.imageView1);
BitmapDrawable frame1=(BitmapDrawable)getResources().getDrawable(R.drawable.subh_navratri);
BitmapDrawable frame=(BitmapDrawable)getResources().getDrawable(R.drawable.index);
BitmapDrawable frame2=(BitmapDrawable)getResources().getDrawable(R.drawable.icon);
int resonableduration=250;
manimation.addFrame(frame1, resonableduration);
manimation.addFrame(frame, resonableduration);
manimation.addFrame(frame2, resonableduration);
iv.setBackgroundDrawable(manimation);
manimation.setOneShot(false);
manimation.start();
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
manimation.stop();
}
});
}
}
2] Create XML File In res/main.xml then put code this:
Note:Take Two Button And One Imageview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Animation Effect" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop Animation Effect" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="377dp"
android:layout_height="235dp"
android:layout_weight="0.89" >
</ImageView>
</LinearLayout>


Comments
Post a Comment