1.在res下新建anim文件夹,在其下新建四个xml文件,分别对应那四种动画效果
首先修改四个xml的set
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator">
2.main.xml中的一幅图和四个按钮不变,主文件里声明对象,获取对象,绑定监听器,也一样。
3.监听器改变了,变简单了
Animation animation = AnimationUtils.loadAnimation(animation.this, R.anim.alpha);
imageView.startAnimation(animation);
4.详细说下四个动画的xml
<alpha
android:fromAlpha="1.0" 从完全不透明
android:toAlpha="0.0" 到完全透明
android:startOffset="500" 变化前先休眠500毫秒
android:duration="500"/> 整个变化过程用时500毫秒
<translate
android:fromXDelta="50%" x轴的起点是当前自己x位置右移50%
android:toXDelta="100%" x轴的终点是当前自己x位置右移100%
android:fromYDelta="0%" y轴的起点是当前自己y位置
android:toYDelta="100%" y轴的重点是当前自己y位置右移100%
android:duration="2000" /> 整个变化过程用时2000毫秒
<rotate
android:fromDegrees="0" 起始角度0
android:toDegrees="+350" 终止角度正350
android:pivotX="50%" 旋转中心点的x轴为自身x的50%
android:pivotY="50%" 旋转中心点的y轴为自身y的50%
android:duration="5000"/> 整个变化过程用时5000毫秒
<scale
android:fromXScale="1.0" x轴从1.0,即完全大小
android:toXScale="0.0" 缩放到0.0,即没了
android:fromYScale="1.0" y轴一样
android:toYScale="0.0"
android:pivotX="50%" 缩放中心的x轴为自身x的50%
android:pivotY="50%" 缩放中心的y轴为自身y的50%
android:duration="2000" /> 整个变化过程用时2000毫秒
关于缩放,移动,旋转的中心点
使用“50”就是绝对位置
使用“50%”就是以自身为参照
使用“50%p”就是以父控件为参照
代码