Here is the example for simple android animation using <animation-list/> in Drawable Folder in android.
Here is the java code for Simple Animation
<!---------------------------- --------------------------------------------->
public class AnimationSimpleActivity extends Activity {
ImageView mImageView;
private AnimationDrawable introDrawable;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView=(ImageView)findViewById(R.id.animation);
mImageView.setBackgroundResource(R.drawable.myanimation);
introDrawable=(AnimationDrawable)mImageView.getBackground();
mImageView.post(new Animator());
}
private long starttime,endtime;
private class Animator implements Runnable {
public void run() {
starttime=System.currentTimeMillis();
introDrawable.start();
Timer mTimer=new Timer();
mTimer.schedule(new ActivityChanger(), 3000);
}
}
public class ActivityChanger extends TimerTask{
@Override
public void run() {
endtime = System.currentTimeMillis();
if(endtime-starttime >=1800){
AnimationSimpleActivity.this.finish();
Intent mIntent=new Intent(AnimationSimpleActivity.this, Activity2.class);
startActivity(mIntent);
}
}
}
}
Below is the xml file for animation-list res/drawable/myanimation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/f1" android:duration="200"/>
<item android:drawable="@drawable/f2" android:duration="200"/>
<item android:drawable="@drawable/f3" android:duration="200"/>
<item android:drawable="@drawable/f4" android:duration="200"/>
<item android:drawable="@drawable/f5" android:duration="200"/>
<item android:drawable="@drawable/f6" android:duration="200"/>
<item android:drawable="@drawable/f7" android:duration="200"/>
<item android:drawable="@drawable/f8" android:duration="200"/>
<item android:drawable="@drawable/f9" android:duration="200"/>
</animation-list>
Here is the output:
Here is the java code for Simple Animation
<!---------------------------- --------------------------------------------->
public class AnimationSimpleActivity extends Activity {
ImageView mImageView;
private AnimationDrawable introDrawable;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView=(ImageView)findViewById(R.id.animation);
mImageView.setBackgroundResource(R.drawable.myanimation);
introDrawable=(AnimationDrawable)mImageView.getBackground();
mImageView.post(new Animator());
}
private long starttime,endtime;
private class Animator implements Runnable {
public void run() {
starttime=System.currentTimeMillis();
introDrawable.start();
Timer mTimer=new Timer();
mTimer.schedule(new ActivityChanger(), 3000);
}
}
public class ActivityChanger extends TimerTask{
@Override
public void run() {
endtime = System.currentTimeMillis();
if(endtime-starttime >=1800){
AnimationSimpleActivity.this.finish();
Intent mIntent=new Intent(AnimationSimpleActivity.this, Activity2.class);
startActivity(mIntent);
}
}
}
}
Below is the xml file for animation-list res/drawable/myanimation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/f1" android:duration="200"/>
<item android:drawable="@drawable/f2" android:duration="200"/>
<item android:drawable="@drawable/f3" android:duration="200"/>
<item android:drawable="@drawable/f4" android:duration="200"/>
<item android:drawable="@drawable/f5" android:duration="200"/>
<item android:drawable="@drawable/f6" android:duration="200"/>
<item android:drawable="@drawable/f7" android:duration="200"/>
<item android:drawable="@drawable/f8" android:duration="200"/>
<item android:drawable="@drawable/f9" android:duration="200"/>
</animation-list>
Here is the output:
No comments:
Post a Comment