ObjectAnimator基本用法

//参数一:要操纵的view;
//参数二:要操纵的属性(translationX、translationY、rotationX、rotationY、rotation、scaleX、scaleY, alpha)
//参数三:可变数组参数,代表属性变化的一个取值过程。
ObjectAnimator translationX = ObjectAnimator.ofFloat(mTestView, “translationX”, 300);

PropertyValuesHolder 混合效果
   PropertyValuesHolder rotationHolder = PropertyValuesHolder.ofFloat("rotation", 0f, 180f);
   PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.5f, 1f);
   PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.5f, 1f);
   PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0.0f, 1.0f);
   ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, rotationHolder, scaleX, scaleY, alpha);
   animator.setDuration(2000);
   animator.start();

	或者
	PropertyValuesHolder rotationHolder = PropertyValuesHolder.ofFloat("rotation", 0f, 180f);

        PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.5f, 1f);
        PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.5f, 1f);

        PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0.0f, 1.0f);

        ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(ivBg, scaleX, scaleY, alpha);
        animator.setDuration(300);

        ObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(ivBg, rotationHolder);
        rotationAnim.setDuration(2000);

        AnimatorSet set = new AnimatorSet();
        set.playTogether(animator, rotationAnim);
        set.start();
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                dismiss();
            }
        });

tips

PropertyValuesHolder alpha1 = PropertyValuesHolder.ofFloat(“alpha”, 0.0f, 1.0f);
PropertyValuesHolder alphaOut = PropertyValuesHolder.ofFloat(“alpha”, 1.0f, 0.0f);
PropertyValuesHolder scaleX1 = PropertyValuesHolder.ofFloat(“scaleX”, 0.5f, 1.05f, 1.0f);
PropertyValuesHolder scaleY1 = PropertyValuesHolder.ofFloat(“scaleY”, 0.5f, 1.05f, 1.0f);

  1. scale 和 alpha 执行动画时需要先隐藏targetView,否则效果会有先出现比较诡异的效果
  2. 先调用addListener()再调用start()否则某些情况可能没有回调onAnimationStart()中的逻辑
  3. ObjectAnimator 调用addListener #onAnimationStart 可以看到预期效果,但是,在AnimatorSet 中使用 Animatoron onAnimationStart 不会按delay时间执行maybe this is bug。

BounceInterpolator 回弹效果

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