[java]代码库
package com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
public class MainAnimation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 定义UI组件
final ImageButton ib1 = (ImageButton) findViewById(R.id.ImageButton01);
final ImageButton ib2 = (ImageButton) findViewById(R.id.ImageButton02);
final ImageButton ib3 = (ImageButton) findViewById(R.id.ImageButton03);
final ImageButton ib4 = (ImageButton) findViewById(R.id.ImageButton04);
final ImageButton ib5 = (ImageButton) findViewById(R.id.ImageButton05);
// 定义监听器
OnClickListener ocl = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ImageButton01:
// 创建Animation对象
Animation ani1 = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.alpha_animation);
// 组件播放动画
ib1.startAnimation(ani1);
break;
case R.id.ImageButton02:
Animation ani2 = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.scale_animation);
ib2.startAnimation(ani2);
break;
case R.id.ImageButton03:
Animation ani3 = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.translate_animation);
ib3.startAnimation(ani3);
break;
case R.id.ImageButton04:
Animation ani4 = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.rotate_animation);
ib4.startAnimation(ani4);
break;
case R.id.ImageButton05:
Animation ani5 = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.composite_animation);
ib5.startAnimation(ani5);
break;
}
}
};
// 绑定监听器
ib1.setOnClickListener(ocl);
ib2.setOnClickListener(ocl);
ib3.setOnClickListener(ocl);
ib4.setOnClickListener(ocl);
ib5.setOnClickListener(ocl);
}
}