packageorg.shuxiang.test;importandroid.app.Activity;importandroid.graphics.drawable.AnimationDrawable;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.view.Window;importandroid.widget.Button;importandroid.widget.ImageView;public class Activity10 extendsActivity
{privateImageView animationIV;privateButton buttonA, buttonB, buttonC;privateAnimationDrawable animationDrawable;
@Overridepublic voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test10);
animationIV=(ImageView) findViewById(R.id.animationIV);
buttonA=(Button) findViewById(R.id.buttonA);
buttonB=(Button) findViewById(R.id.buttonB);
buttonC=(Button) findViewById(R.id.buttonC);
buttonA.setOnClickListener(newOnClickListener()
{
@Overridepublic voidonClick(View v) {//TODO Auto-generated method stub
animationIV.setImageResource(R.drawable.animation1);
animationDrawable=(AnimationDrawable) animationIV.getDrawable();
animationDrawable.start();
}
});
buttonB.setOnClickListener(newOnClickListener()
{
@Overridepublic voidonClick(View v) {//TODO Auto-generated method stub
animationDrawable =(AnimationDrawable) animationIV.getDrawable();
animationDrawable.stop();
}
});
buttonC.setOnClickListener(newOnClickListener()
{
@Overridepublic voidonClick(View v) {//TODO Auto-generated method stub
animationIV.setImageResource(R.drawable.animation2);
animationDrawable=(AnimationDrawable) animationIV.getDrawable();
animationDrawable.start();
}
});
}
}