ObjectAnimator常用属性:
translationX、translationY ;rotation、rotationX、rotationY ;scaleX、scaleY ; X、Y; alpha;
常用方法、类:
ValueAnimator、ObjectAnimator、AnimatorUpdateListener、AnimatorListenerAdapter、PropertyValuesHolder、AnimatorSet、TypeEvalueators、Interpolators
差值器Interpolato
动画的使用
public void move(View view){
// TranslateAnimation animation = new TranslateAnimation(0,200, 0,0);
// animation.setDuration(1000);
// animation.setFillAfter(true);
//
// imageView.startAnimation(animation);
// <一 :ObjectAnimator>
// ObjectAnimator.ofFloat(imageView, "rotation", 0, 360F).setDuration(1000).start();
// ObjectAnimator.ofFloat(imageView, "translationX", 0, 200F).setDuration(1000).start();
// ObjectAnimator.ofFloat(imageView, "translationY", 0, 200F).setDuration(1000).start();
//
// <二:PropertyValuesHolder>
// PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("rotation",0,360F);
// PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("translationX",0,200F);
// PropertyValuesHolder p3 = PropertyValuesHolder.ofFloat("translationY",0,200F);
// ObjectAnimator.ofPropertyValuesHolder(imageView, p1, p2, p3).setDuration(1000).start();
<三:ObjectAnimator--AnimatorSet可以修改动画顺序>
ObjectAnimator animation1 = ObjectAnimator.ofFloat( imageView, "rotation",0,360F);
ObjectAnimator animation2 = ObjectAnimator.ofFloat( imageView, "translationX",0,200F);
ObjectAnimator animation3 = ObjectAnimator.ofFloat( imageView, "translationY",0,200F);
AnimatorSet set = new AnimatorSet();
// set.playTogether(animation1, animation2, animation3);
// set.playSequentially(animation1,animation3,animation2);
set.play(animation1).with(animation2);
set.play(animation3).before(animation2);
set.setDuration(1000);
set.start();
}
监听动画
anim.addListener( new AnimatorListenerAdapter() {
@Override
//不用完全实现Listener方法
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
Toast. makeText(ListenAnimActivity. this, "Animation end" , Toast.LENGTH_LONG ).show();
}
});
//anim.addListener(new AnimatorListener() {
//
// @Override
// public void onAnimationStart(Animator animation) {
// }
//
// @Override
// public void onAnimationRepeat(Animator animation) {
// }
//
// @Override
// public void onAnimationEnd(Animator animation) {
// Toast.makeText(ListenAnimActivity.this, "Animation end", Toast.LENGTH_LONG).show();
//
// }
//
// @Override
// public void onAnimationCancel(Animator animation) {
// }
// });
ValueAnimator
// final Button button = (Button) view;
// 产生0~100随机数
// ValueAnimator animator = ValueAnimator.ofInt(0, 100);
// animator.setDuration(5000);
// animator.addUpdateListener(new AnimatorUpdateListener() {
//
// @Override
// public void onAnimationUpdate(ValueAnimator animation) {
// Integer value = (Integer) animation.getAnimatedValue();
// button.setText("" + value);
// }
// });
// animator.start();