public class MainActivity extends AppCompatActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
//参数1:要执行动画的 控件 对象
//参数2:要实行动画的 样式字符串
//参数3:可变长度的参数 用来确定该控件对象的 改变过程
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "alpha", 1f, 0f, 1f, 0.5f, 1f);
animator.setDuration(5000);
// animator.start();
float x = tv.getTranslationX();
ObjectAnimator animator1 = ObjectAnimator.ofFloat(tv, "translationX", x , 100, x);
animator1.setDuration(5000);
// animator1.start();
ObjectAnimator animator2 = ObjectAnimator.ofFloat(tv, "scaleY", 1f, 0.5f, 2f, 1f);
animator2.setDuration(5000);
//--------------------------------
ValueAnimator animator3 = ValueAnimator.ofObject(new ArgbEvaluator(), Color.RED, Color.BLUE);
animator3.setDuration(5000);
animator3.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int currentColor = (int) animation.getAnimatedValue();
tv.setTextColor(currentColor);
}
});
// animator3.start();
AnimatorSet set = new AnimatorSet();
set.play(animator).after(animator1).before(animator2).with(animator3);
set.start();
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
}
});
}
}
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
//参数1:要执行动画的 控件 对象
//参数2:要实行动画的 样式字符串
//参数3:可变长度的参数 用来确定该控件对象的 改变过程
ObjectAnimator animator = ObjectAnimator.ofFloat(tv, "alpha", 1f, 0f, 1f, 0.5f, 1f);
animator.setDuration(5000);
// animator.start();
float x = tv.getTranslationX();
ObjectAnimator animator1 = ObjectAnimator.ofFloat(tv, "translationX", x , 100, x);
animator1.setDuration(5000);
// animator1.start();
ObjectAnimator animator2 = ObjectAnimator.ofFloat(tv, "scaleY", 1f, 0.5f, 2f, 1f);
animator2.setDuration(5000);
//--------------------------------
ValueAnimator animator3 = ValueAnimator.ofObject(new ArgbEvaluator(), Color.RED, Color.BLUE);
animator3.setDuration(5000);
animator3.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int currentColor = (int) animation.getAnimatedValue();
tv.setTextColor(currentColor);
}
});
// animator3.start();
AnimatorSet set = new AnimatorSet();
set.play(animator).after(animator1).before(animator2).with(animator3);
set.start();
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
}
});
}
}