2

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

我正在使用 Nineoldandroid 库来做到这一点。但是有这部分是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" ?

4

1 回答 1

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));
于 2014-08-30T14:08:36.183 回答