Jak*_*kob 22 animation android android-animation
使用Animator类,您可以简单地调用类似下面的内容来同时播放多个动画:
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(animatorsArray);
animatorSet.start();
Run Code Online (Sandbox Code Playgroud)
但我找不到任何与ViewPropertyAnimator兼容的类似内容.
(仅供参考.我正在尝试为多个listView项目制作动画)
Bar*_*ski 13
我知道这个问题超过一年了,但由于我需要同样的东西,我想出了一个解决方案,我决定分享它:
我已经创建了一个ObjectAnimator包装器,您可以使用几乎完全相同的方式使用它ViewPropertyAnimator.而且,您仍然可以使用该ObjectAnimator对象,以便您可以编写AnimatorSet.
该包装可在这里.
示例(为a设置相同参数的动画mTestView):
ViewPropertyAnimatormTestView.animate().withLayer().alphaBy(0.3f).rotationX(27);
Run Code Online (Sandbox Code Playgroud)
ViewPropertyObjectAnimator (我的包装)ObjectAnimator objectAnimator =
ViewPropertyObjectAnimator.animate(mTestView).withLayer().alphaBy(0.3f).rotationX(27).get();
Run Code Online (Sandbox Code Playgroud)
你有一个ObjectAnimator你可以在start()里面或在里面使用AnimatorSet.
我建议使用上面提到的 withStartAction 。
进一步阅读Android 文档中的ViewPropertyAnimator页面
public ViewPropertyAnimator withStartAction (Runnable runnable) 在 API 级别 16 中添加
指定在下一个动画运行时发生的动作。如果在此 ViewPropertyAnimator 上设置了 startDelay,则该操作将在 startDelay 到期后运行,当实际动画开始时。此方法与 withEndAction(Runnable) 一起,旨在帮助使用应用程序中的其他动画或动作来帮助编排 ViewPropertyAnimator 动画。
我即将自己使用它,看起来它正在工作。
我将所有动画代码添加到 Runnable 中,将多个 Runnable 添加到 ArrayList 中,准备就绪后,我循环遍历 ArrayList 并在所有这些代码上调用 run()。