之前的寫法
ObjectAnimator animatorAlphaTwo = ObjectAnimator.ofFloat(rlLay,"alpha",0f,1f);
animatorAlphaTwo.setDuration(400);
ObjectAnimator animatorTranTwo = ObjectAnimator.ofFloat(rlLay,"TranslationX",300f,0f);
animatorTranTwo.setStartDelay(400);
AnimatorSet animatorSettwo = new AnimatorSet();
animatorSettwo.play(animatorAlphaTwo).with(animatorTranTwo);
animatorSettwo.setInterpolator(new LinearInterpolator());
animatorSettwo.setDuration(2000);
animatorSettwo.start();
優(yōu)化后的寫法
PropertyValuesHolder animatorAlpha = PropertyValuesHolder.ofFloat("alpha",0f,1f);
PropertyValuesHolder animatorTran = PropertyValuesHolder.ofFloat("TranslationX",300f,0f,80f,0f);
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(rlLay,animatorAlpha,animatorTran);
animator.setStartDelay(300);
animator.setDuration(2000);
animator.start();