使用Nineoldandroids移植缩放视图 - 方法未解决

时间:2014-08-30 12:56:26

标签: android animation nineoldandroids

我正在尝试将http://developer.android.com/training/animation/zoom.html移回API< 11。

我正在使用nineoldandroid库这样做。然而,这部分是九折的人无法理解的:

        AnimatorSet set = new AnimatorSet();
        set.play(ObjectAnimator
                .ofFloat(expandedImageView, View.X, startBounds.left))
                .with(ObjectAnimator
                        .ofFloat(expandedImageView,
                                View.Y, startBounds.top))
                .with(ObjectAnimator
                        .ofFloat(expandedImageView,
                                View.SCALE_X, startScaleFinal))
                .with(ObjectAnimator
                        .ofFloat(expandedImageView,
                                View.SCALE_Y, startScaleFinal));

我把它变成了:

AnimatorSet set = new AnimatorSet();
set.playTogether(
        ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left),
        ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top),
        ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f),
        ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)
);

但不接受View.X,View.Y,View.SCALE_X和View.SCALE_Y。

是否应将这些字符串替换为“translationX”,translationY“和”scaleX“,”scaleY“?

1 个答案:

答案 0 :(得分:2)

我最初的猜测是正确的,但不需要playTogether。

这是解决方案:

set
        .play(ObjectAnimator.ofFloat(expandedImageView, "translationX", startBounds.left, finalBounds.left))
        .with(ObjectAnimator.ofFloat(expandedImageView, "translationY", startBounds.top, finalBounds.top))
        .with(ObjectAnimator.ofFloat(expandedImageView, "scaleX", startScale, 1f))
        .with(ObjectAnimator.ofFloat(expandedImageView, "scaleY", startScale, 1f));