Android 跌落动画

通过RotateAnimation实现二次旋转动画实现(使用BounceInterpolator加速弹跳插值器)
//计算跌落度数对应的中心点位置
final double rw=iv.getWidth()-iv.getWidth()*Math.cos(Math.toRadians(dusu));
final double rh=iv.getWidth()*Math.sin(Math.toRadians(dusu));
iv.setTranslationX(-(int)(rw));
iv.setTranslationY(-(int)rh);
//设置第一次跌落动画
Animation rotateAnimation = new RotateAnimation(0, -dusu, (float)(iv.getWidth()-rw),(float)-rh);
rotateAnimation.setFillAfter(true);
rotateAnimation.setDuration(1000);
rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//先设置移动到原点
iv.setTranslationX(0);
iv.setTranslationY(0);
//执行第二次跌落动画
Animation rotateAnimation = new RotateAnimation(-dusu,0,0,0);
rotateAnimation.setFillAfter(true);
rotateAnimation.setDuration(1000);
rotateAnimation.setInterpolator(new BounceInterpolator());
iv.startAnimation(rotateAnimation);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
rotateAnimation.setInterpolator(new BounceInterpolator());
iv.startAnimation(rotateAnimation);
图表动画效果实现
绘制图表时,需要执行动画的Y坐标 乘以Delta
通过Android里面得动画插值器从 0-1 改变Delta值达到理想动画效果

本文介绍了一种在Android中实现物体跌落动画的方法,通过两次使用RotateAnimation结合BounceInterpolator来模拟物体跌落并弹起的过程。首次动画将物体倾斜至一定角度,随后通过平移至原点并启动第二次动画实现反弹效果。
403

被折叠的 条评论
为什么被折叠?



