Android动画详解-补间动画-AnimationSet
2017-10-11 09:26
387 查看
在之前呢,我们使用的都是单个补间动画的效果,当然这几种效果可以进行叠加使用,无论是相同种类还是不同种类之间都可以。
那么我们准备实现怎样的动画呢?
我实事先准备一个圆形图片(随便P的)放在屏幕的左上角,让它模拟平抛运动到达屏幕的右下角,同时小球绕中心旋转。
通过Java代码实现动画效果
注:animationY.setInterpolator(new AccelerateInterpolator());
设置运动的速度方式,该方式是内置的匀加速运动,默认是匀速运动。
附相关速度参数:
AnimationSet当然也可以通过xml定义实现,但是本例中不能使用,主要是需要在代码中动态的获取屏幕的高度和宽度,而在xml都是通过相对控件的相对比例进行变换的。
那么我们准备实现怎样的动画呢?
我实事先准备一个圆形图片(随便P的)放在屏幕的左上角,让它模拟平抛运动到达屏幕的右下角,同时小球绕中心旋转。
通过Java代码实现动画效果
AnimationSet animationSet = new AnimationSet(false); animationSet.setFillAfter(true); TranslateAnimation animationX = new TranslateAnimation(0, width - image_x, 0, 0); animationX.setDuration(4000); TranslateAnimation animationY = new TranslateAnimation(0, 0, 0, height - image_y); animationY.setInterpolator(new AccelerateInterpolator()); animationY.setDuration(4000); RotateAnimation rotateAnimation=new RotateAnimation(0, 1080, image_x/2, image_x/2); rotateAnimation.setDuration(4000); rotateAnimation.setInterpolator(new AccelerateInterpolator()); animationSet.addAnimation(rotateAnimation); animationSet.addAnimation(animationX); animationSet.addAnimation(animationY); imageView1.startAnimation(animationSet); animationSet.start();
注:animationY.setInterpolator(new AccelerateInterpolator());
设置运动的速度方式,该方式是内置的匀加速运动,默认是匀速运动。
附相关速度参数:
/** * android:interpolator="@android:anim/accelerate_interpolator" * 设置动画为加速动画(动画播放中越来越快) * * android:interpolator="@android:anim/decelerate_interpolator" * 设置动画为减速动画(动画播放中越来越慢) 4000 * * android:interpolator="@android:anim/accelerate_decelerate_interpolator" * 设置动画为先加速在减速(开始速度最快 逐渐减慢) * * android:interpolator="@android:anim/anticipate_interpolator" * 先反向执行一段,然后再加速反向回来(相当于我们弹簧,先反向压缩一小段,然后在加速弹出) * * android:interpolator="@android:anim/anticipate_overshoot_interpolator" * 同上先反向一段,然后加速反向回来,执行完毕自带回弹效果(更形象的弹簧效果) * * android:interpolator="@android:anim/bounce_interpolator" * 执行完毕之后会回弹跳跃几段(相当于我们高空掉下一颗皮球,到地面是会跳动几下) * * android:interpolator="@android:anim/cycle_interpolator" * 循环,动画循环一定次数,值的改变为一正弦函数:Math.sin(2* mCycles* Math.PI* input) * * android:interpolator="@android:anim/linear_interpolator" 线性均匀改变 * * android:interpolator="@android:anim/overshoot_interpolator" 加速执行,结束之后回弹 */
AnimationSet当然也可以通过xml定义实现,但是本例中不能使用,主要是需要在代码中动态的获取屏幕的高度和宽度,而在xml都是通过相对控件的相对比例进行变换的。
相关文章推荐
- Android补间动画之ScaleAnimation、AlphaAnimation、RotateAnimation、TranslateAnimation、AnimationSet详解
- Android帧动画、补间动画、属性动画用法详解
- Android 动画系列之补间(Tween)动画详解
- Android两大动画之Tween(补间动画)详解
- android 补间动画详解
- Android动画之补间动画(Tween Animation)实例详解
- Android补间动画效果translate、scale、alpha、rotate详解(带源码)XML实现
- Android补间动画之alpha、scale、translate、rotate、set详解
- Android动画机制(1):帧动画、补间动画详解及实战演练
- Android 属性动画,补间动画,xml资源动画详解
- Android补间动画(TweenedAnimations)详解
- android之逐帧,补间动画详解。
- Android动画详解-补间动画-基础篇
- Android 动画使用详解(二) 补间动画
- Android基础笔记(十)- 帧动画、补间动画详解、对话框
- Android动画 详解(一 补间动画)
- Android动画详解(二) 补间动画
- Android Animation动画详解(一): 补间动画
- Android--Animotion动画详解-逐帧动画,补间动画,属性动画。
- Android动画详解-补间动画-activity切换动画实现