- 首页 > it技术 > >
AnimatorSet|AnimatorSet 动画集合以及它的监听事件
iv=findViewById(R.id.iv);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
model2();
}
});
}private void model2() {
AnimatorSet animatorset=new AnimatorSet();
//平移
ObjectAnimator transy = ObjectAnimator.ofFloat(iv, View.TRANSLATION_Y, 0, 150);
//旋转
ObjectAnimator rotateq = ObjectAnimator.ofFloat(iv, View.ROTATION, 0, 360);
//缩放
ObjectAnimator aFloatx = ObjectAnimator.ofFloat(iv, View.SCALE_X, 0.3f, 1.0f);
//透明度
ObjectAnimator aFloatq = ObjectAnimator.ofFloat(iv, View.ALPHA, 0.3f, 1.0f);
//playTogether这个属性是一起执行
// animatorset.playTogether(transy,rotateq);
//playSequentially是按照顺序执行一个一个执行
//animatorset.playSequentially(transy,rotateq);
//play只能执行一个 after先执行,with平移和缩放一起执行,before最后执行
//animatorset.play(transy).with(rotateq).before(aFloatq).after(aFloatx);
//设置每个动画开始的时间
transy.setStartDelay(1000l);
rotateq.setStartDelay(1000l);
animatorset.play(transy).with(rotateq).before(aFloatq).after(aFloatx);
;
animatorset.setDuration(3000);
animatorset.start();
animatorset.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {}@Override
public void onAnimationEnd(Animator animator) {
Toast.makeText(MainActivity.this, "Hello Toast,Toast(吐司)来了", Toast.LENGTH_LONG).show();
}@Override
public void onAnimationCancel(Animator animator) {}@Override
public void onAnimationRepeat(Animator animator) {}
});
}
}
推荐阅读