public class Animation_XML_Activity extends Activity { private Button button1; private Button button2; private Button button3; private Button button4; private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_animation__xml_); button1=(Button)findViewById(R.id.button_alpha); button2=(Button)findViewById(R.id.button_rotate); button3=(Button)findViewById(R.id.button_scale); button4=(Button)findViewById(R.id.button_translate); imageView=(ImageView)findViewById(R.id.imageview); button1.setOnClickListener(new MyButton()); button2.setOnClickListener(new MyButton()); button3.setOnClickListener(new MyButton()); button4.setOnClickListener(new MyButton()); } class MyButton implements OnClickListener{ @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.button_alpha: Alpha(); break; case R.id.button_rotate: Rotate(); break; case R.id.button_scale: Scale(); break; case R.id.button_translate: Translate(); break; default: break; } }
} public void Alpha() { Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.alpha); imageView.startAnimation(animation); } public void Rotate() { Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.rotate); imageView.startAnimation(animation); } public void Scale() { Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.scale); imageView.startAnimation(animation); } public void Translate() { Animation animation=AnimationUtils.loadAnimation(Animation_XML_Activity.this, R.anim.translate); imageView.startAnimation(animation); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_animation__xml_, menu); return true; } }