我试图在每次按下按钮时使用ViewPropertyAnimator来缩放视图(一个不确定的ProgressBar)。
loadingCircle.animate().scaleY(1.5f).scaleX(1.5f).setDuration(100f);我有一个animatorListener,它可以缩小到正常的onAnimationEnd:
loadingCircle.animate().scaleY(1.0f).scaleX(1.0f).setDuration(100f);没什么复杂的。然而,它似乎并不总是同时缩放x和y。
通常它第一次做对,有时第二次正确。当它不能工作时,它只会激活链中的最后一个操作。如果它是scaleX,它只会缩放X。如果我把它互换,它只会缩放Y。
scaleX和scaleY的文档说明:
已经在该属性上运行的动画将被取消。
然而,我认为ViewPropertyAnimator可以被链接,这个注释只适用于新的动画(在不同的代码行上)。我是不是做错什么了,还是我发现了窃听器?
我在GalaxyS4上运行Android4.2.2。股票ROM,但根深蒂固。如果这有区别的话。
发布于 2015-05-20 17:03:15
我相信这确实是个错误。为此,我使用ObjectAnimator而不是ViewPropertyAnimator来获得相同的结果。所以,你的看起来就像:
ObjectAnimator animX = ObjectAnimator.ofFloat(loadingCircle, "scaleX", 1.0f);
ObjectAnimator animY = ObjectAnimator.ofFloat(loadingCircle, "scaleY", 1.0f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();来源:http://developer.android.com/guide/topics/graphics/prop-animation.html#view-prop-animator
发布于 2015-05-20 17:24:15
阅读源代码,你所描述的行为是完全有意义的,而且是经过设计的。添加动画时,它将在下一次运行循环/可能时启动。有时你可以在这之前把两个动画都放进去,有时你不能。
如果您告诉它不要立即启动动画,那么您将有足够的时间添加所有的动画。这显然是个小问题。
你也许可以试试这样的方法:
loadingCircle.animate()
.setStartDelay(1000) //prevent the animation from starting
.scaleY(1.5f)
.scaleX(1.5f)
.setDuration(100f)
.setStartDelay(0)
.start();发布于 2015-11-09 08:21:59
AnimatorSet set = new AnimatorSet();
set.setInterpolator(new AccelerateInterpolator());
set.setDuration(100l);
view.setPivotX(halfWidth);
view.setPivotY(helfHeight);
set.play(ObjectAnimator.ofFloat(view, View.SCALE_X, 0f, 1f))
.with(ObjectAnimator.ofFloat(hRippleAdd, View.SCALE_Y, 0f, 1f));
set.start();https://stackoverflow.com/questions/26024555
复制相似问题