/**
* Tween 补间动画
*
* @author lilin
* @date 2011-9-5 下午04:03:40
* @ClassName: Main
* @Description: 通过硬编码的方式
*/
public class Main extends Activity implements OnClickListener {
private Button b1, b2, b3, b4;
private ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView) findViewById(R.id.ImageView01);
b1 = (Button) findViewById(R.id.Button01);
b2 = (Button) findViewById(R.id.Button02);
b3 = (Button) findViewById(R.id.Button03);
b4 = (Button) findViewById(R.id.Button04);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Button01:// 创建Sacle(尺寸)变化动画
Animation scaleAnimation = new ScaleAnimation(//
0f, // 起始X坐标上的伸缩尺寸
1f,// 结束X坐标上的伸缩尺寸
0f, // 起始Y坐标上的伸缩尺寸
1f,// 结束Y坐标上的伸缩尺寸
Animation.RELATIVE_TO_SELF,// X坐标伸缩模式
0.5f,// X坐标伸缩值
Animation.RELATIVE_TO_SELF,// Y坐标伸缩模式
0.5f// Y坐标伸缩值
);
scaleAnimation.setDuration(3000);// 创建Sacle(尺寸)变化动画
imageView.startAnimation(scaleAnimation);// 开始动画
break;
case R.id.Button02:// 创建Alpha(渐变)动画
Animation alphaAnimation = new AlphaAnimation(//
0.1f,// 动画开始透明度
1.0f// 动画结束透明度(取值范围0.0-1.0)
);
alphaAnimation.setDuration(3000);
imageView.startAnimation(alphaAnimation);
break;
case R.id.Button03:// 创建translate(位置变化)动画
Animation translateAnimation = new TranslateAnimation(//
10,// 起始X坐标
100, // 结束X坐标
10,// 起始Y坐标
100// 结束Y坐标
);
translateAnimation.setDuration(3000);
imageView.startAnimation(translateAnimation);
break;
case R.id.Button04:// 创建rotate(旋转)动画
Animation rotateAnimation = new RotateAnimation(//
0f, // 旋转开始角度
+360f,// 旋转结束角度
Animation.RELATIVE_TO_SELF, // X坐标伸缩模式
0.5f,// X坐标伸缩值
Animation.RELATIVE_TO_SELF, // Y坐标伸缩模式
0.5f// Y坐标伸缩值
);
rotateAnimation.setDuration(3000);
imageView.startAnimation(rotateAnimation);
break;
default:
break;
}
}
}