1》首先是Animation 动画监听,开始,结束的控制
private ImageView yun_left; private Animation myAnimation_Translate_left, myAnimation_Translate_right;
2》
myAnimation_Translate_left = AnimationUtils.loadAnimation(this, R.anim.my_translate_action_left); myAnimation_Translate_right = AnimationUtils.loadAnimation(this, R.anim.my_translate_action_right);
3》
myAnimation_Translate_left .setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { randomDuration(); myAnimation_Translate_left.setDuration(number); yun_left.startAnimation(myAnimation_Translate_right); } }); myAnimation_Translate_right .setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { randomDuration(); myAnimation_Translate_left.setDuration(number); yun_left.startAnimation(myAnimation_Translate_left); } }); yun_left.startAnimation(myAnimation_Translate_left);
4》定义xml布局
向右移动
my_translate_action_right
xmlns:android="http://schemas.android.com/apk/res/android">
5》向左移动
my_translate_action_left
xmlns:android="http://schemas.android.com/apk/res/android">
2.接下来是ObjectAnimator动画实现贝塞尔曲线样式
1》创建对象
ObjectAnimatoranimatorX,animatorY;
animatorX = ObjectAnimator.ofFloat(same_level, "X",0,600).setDuration(1000); animatorY = ObjectAnimator.ofFloat(same_level, "Y",800,200).setDuration(1000);
//设置监听
animatorY.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) {}@Override public void onAnimationEnd(Animator animation) { MyToast.showToast(SameCaseActy.this,im.getScaleX()+""); }@Override public void onAnimationCancel(Animator animation) {}@Override public void onAnimationRepeat(Animator animation) {} });
//开始动画
same_level.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {animatorY.setInterpolator(new LinearInterpolator()); animatorX.setInterpolator(new PathInterpolator(0.4f,0,0.2f,1)); animatorX.start(); animatorY.start(); } });
【关于Android动画的监听,开始,结束的控制分别有 Animation 动画和 ObjectAnimator 动画】