import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class AnimationEx extends Activity {
/** Called when the activity is first created. */
Button b1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
parentButtonClicked(v);
/*ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setBackgroundResource(R.drawable.ani);
AnimationDrawable ad=(AnimationDrawable)img.getBackground();
*/
}
});
}
private void parentButtonClicked(View v)
{
animate();
}
private void animate()
{
ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setBackgroundResource(R.drawable.ani);
AnimationDrawable ad=(AnimationDrawable)img.getBackground();
if(ad.isRunning())
{
ad.stop();
b1.setText("start");
}
else
{
ad.start();
b1.setText("stop");
}
}
}
anim.xml in drawable folder in same folder were your picture or snaps are kept
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@drawable/icon"
android:duration="550" />
<item
android:drawable="@drawable/anim"
android:duration="550" />
<item
android:drawable="@drawable/cute"
android:duration="550"></item>
<item
android:drawable="@drawable/dolphin"
android:duration="550"></item>
<item
android:drawable="@drawable/man"
android:duration="550"></item>
</animation-list>
No comments:
Post a Comment