width是手机的宽度;height是手机的高度;
pop_iv是小球球图片;
iv_width是小球的宽度;iv_heigt是晓求得高度;
主要:在每一个动画监听事件的结束方法里写下一个动画,只能点击按钮转一圈,重复旋转这里么有实现;
if(){}的判断根据自己的要求去改
遇到的问题:
昨天用Tween实现了小球转圈运动,但是在该页面没有重启的时候,小球只保存最后一次if判断的动画效果
TranslateAnimation animation = new TranslateAnimation(0, 0, 0, height - iv_height); animation.setDuration(1000); animation.setFillAfter(true); //动画的监听事件 animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { // float x = pop_iv.getX(); float x = pop_iv.getRotationX(); float y = pop_iv.getY(); System.out.println("animation===x的值是:" + x + "+y的值是:" + y); } @Override public void onAnimationEnd(Animation animation) { if (height - iv_height > 500) { final TranslateAnimation ani = new TranslateAnimation(0, width - 82, height - iv_height, height - iv_height); ani.setDuration(1000); ani.setFillAfter(true); ani.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { float x = pop_iv.getX(); float y = pop_iv.getY(); System.out.println("ani==x的值是:" + x + "+y的值是:" + y); } @Override public void onAnimationEnd(Animation animation) { if (width - iv_width > 200) { TranslateAnimation ani1 = new TranslateAnimation(width - 82, width - 82, height - iv_height, 0); ani1.setDuration(1000); ani1.setFillAfter(true); ani1.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { float x = pop_iv.getX(); float y = pop_iv.getY(); System.out.println("ani1==x的值是:" + x + "+y的值是:" + y); } @Override public void onAnimationEnd(Animation animation) { // if ((width - iv_width == 82)) { TranslateAnimation ani2 = new TranslateAnimation(width - 82, 0, 0, 0); ani2.setDuration(1000); ani2.setFillAfter(true); ani2.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { float x = pop_iv.getX(); float y = pop_iv.getY(); System.out.println("ani2==x的值是:" + x + "+y的值是:" + y); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) {animation.setRepeatCount(-1);} }); pop_iv.startAnimation(ani2); } // } @Override public void onAnimationRepeat(Animation animation) {animation.setRepeatCount(-1);} }); pop_iv.startAnimation(ani1); } } @Override public void onAnimationRepeat(Animation animation) {animation.setRepeatCount(-1);} }); pop_iv.startAnimation(ani); } } @Override public void onAnimationRepeat(Animation animation) {animation.setRepeatCount(-1);} }); pop_iv.startAnimation(animation);