//定义四种类型的Animation
final Animation translAnimation = new TranslateAnimation(0, 300, 0, 300);
final Animation scaleAnimation = new ScaleAnimation(0f, 1f, 0f, 1f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
final Animation alphAnimation = new AlphaAnimation(0.1f, 0.8f);
final Animation rotateAnimation = new RotateAnimation
(0f, 360f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//设置点击事件
bt3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//如果iv1没有选择图片,注意是getDrawable
if (iv1.getDrawable()==null)
{
Toast.makeText(ImChoose.this, "请选择图片", Toast.LENGTH_SHORT).show();
}
else{
//设置延迟时间
translAnimation.setDuration(5000);
scaleAnimation.setDuration(5000);
alphAnimation.setDuration(5000);
rotateAnimation.setDuration(5000);
//定义一个AnimationSet
AnimationSet set = new AnimationSet(true);
//设置set添加四种类型的AnimationSet
set.addAnimation(translAnimation);
set.addAnimation(scaleAnimation);
set.addAnimation(alphAnimation);
set.addAnimation(rotateAnimation);
//设置哪个图片用set
iv1.setAnimation(set);
//启动set
set.startNow(); } } });