Android动画系列之-旋转-Rotate
旋转动画,继承自基类Animaton
使用方式一、xml的方式。比较普遍,而且代码复用性也比较好,推荐使用。步骤如下:
第一步,res目录下新建anim文件夹,在anim目录下新建rotate.xml文件
第二步,编写rotate.xml的内容,示例如下
<rotate
android:fromDegrees="0" #初始角度
android:toDegrees="90" #结束时角度,值为正时顺时针旋转,值为负时逆时针旋转
android:duration="1000" #动画持续时间,单位毫秒
android:interpolator="@android:anim/linear_interpolator" #插值器
android:pivotX="50%" #旋转中心x轴坐标
android:pivotY="50%" #旋转中心y轴坐标
android:repeatCount="0" #重复次数,取值为-1时无限重复,默认动画执行一次
android:repeatMode="reverse" #重复模式,有reverse和restart两个值,前者为倒序回放,后者为重新开始/>
第三步,实例化Rotate动画并执行:
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate);
preview_layout.startAnimation(animation);
使用方式二、代码方式
float fromDegrees = 0;
float toDegrees = 180;
float pivotX = 0.5f;
float pivotY = 0.5f;
RotateAnimation rotateAnimation = new RotateAnimation(fromDegrees, toDegrees, pivotX, pivotY);
rotateAnimation.setDuration(2000);
rotateAnimation.setRepeatCount(2);
rotateAnimation.setRepeatMode(Animation.REVERSE);
rotateAnimation.setInterpolator(this, android.R.anim.accelerate_interpolator);
videoView.startAnimation(rotateAnimation);
Android动画系列之-缩放-Scale
Android动画系列之-渐变-Aplha
Q.E.D.