属性动画:多种动画同时执行

最近项目中要做一个效果,用到属性动画,对一个view执行多个动画,以前用得少,这次使用发现属性动画真是太强大了

ViewHelper.setPivotX(mTvName, 0);
ViewHelper.setPivotY(mTvName, 0);
(1)

PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("translationY", 0, -height);
PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 1, 0.8f);       
PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1, 0.8f);     
PropertyValuesHolder pvhAlpha = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0.5f);
ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(mTvName,
                pvhScaleX, pvhScaleY, pvhY, pvhAlpha);
 objectAnimator.setInterpolator(new LinearInterpolator());
 objectAnimator.setDuration(500);
 objectAnimator.start();

(2)

ObjectAnimator translationYUp = ObjectAnimator.ofFloat(mTvName, "translationY", 0, -height);
ObjectAnimator alpha = ObjectAnimator.ofFloat(mTvName, "alpha", 1, 0.5f);
ObjectAnimator scaleX = ObjectAnimator.ofFloat(mTvName, "scaleX", 1, 0.8f);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(mTvName, "scaleY", 1, 0.8f);
AnimatorSet as = new AnimatorSet();
as.playTogether(translationYUp, alpha, scaleX, scaleY);
as.setDuration(500);
as.start();

写法效果一样

你可能感兴趣的:(android,属性动画)