case Complex:
//设置复杂的操作步骤,点击按钮complex后,会运行四种动画效果叠加
AnimationSet sets = new AnimationSet(false);
//定义渐变动画
AlphaAnimation _animation1 = new AlphaAnimation(1f, 0.1f);
_animation1.setDuration(3000);
//定义旋转动画,在物体的中心位置
RotateAnimation rotateAnimation1 = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation1.setDuration(3000);
//定义缩放动画,从中心坐标开始,缩放1.5倍大小
ScaleAnimation scaleAnimation1 = new ScaleAnimation(1, 1.5f, 1, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation1.setDuration(3000);
//定义移动动画,都从自身坐标开始,移动2个位置
TranslateAnimation translateAnimation1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 2);
translateAnimation1.setDuration(3000);
//启动动画
sets.addAnimation(_animation1);
sets.addAnimation(rotateAnimation1);
sets.addAnimation(scaleAnimation1);
sets.addAnimation(translateAnimation1);
imageView.startAnimation(sets);
break;
default:
break;
}
}
}
}
layout文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/qa" />
<Button
android:id="@+id/Alpha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alpha" />
<Button
android:id="@+id/Rotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rotate" />
<Button
android:id="@+id/Scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scale" />
<Button
android:id="@+id/Translate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Translate" />
<Button
android:id="@+id/Complex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Complex" />
</LinearLayout>
资源anim文件alpha.xml