Android动画支点问题

时间:2017-01-24 11:40:17

标签: android android-animation objectanimator

所以,我的第一个动画是:

ObjectAnimator translation1 = ObjectAnimator.ofFloat(mImage1, "TranslationY", mImage1.getTranslationY(), 0);
    translation1.setDuration(ANIM);
    translation1.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {

        }

        @Override
        public void onAnimationEnd(Animator animator) {
            mImage1.setPivotY(0);

            ObjectAnimator scaleX = ObjectAnimator.ofFloat(mImage1, "scaleX", 1, 0.5f);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(mImage1, "scaleY", 1, 0.5f);
            ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(mImage1, "alpha", mImage1.getAlpha(), 0.1f);
            AnimatorSet set1 = new AnimatorSet();
            set1.playTogether(scaleX, scaleY, alphaAnim);
            set1.setDuration(ANIM);
            set1.start();
        }

        @Override
        public void onAnimationCancel(Animator animator) {

        }

        @Override
        public void onAnimationRepeat(Animator animator) {

        }
    });
    translation1.start();

我将pivotY设置为0,一切正常。

现在,第二部分,因为我缩放了该视图,当我尝试设置枢轴Y或枢轴X时,它是向左/向右/向上/向下移动视图。我尝试过:

mImage1.setPivotX((mImage1.getWidth() * mImage1.getScaleX()) / 100);
    mImage1.setPivotY(mImage1.getHeight() * (-mImage1.getScaleY() * 100) / 100);
    mImage1.setPivotX(-mImage1.getWidth() * mImage1.getScaleX() / 100);

但这些都不起作用。有人可以解释我如何设置枢轴到视图高度和0宽度?

0 个答案:

没有答案