AnimatorSet动画集合同时运行
是的,AnimatorSet可以用来同时运行多个动画。您可以通过调用AnimatorSet的playTogether()方法来指定同时运行的动画。下面是一个示例代码:
AnimatorSet animatorSet = new AnimatorSet();
ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(view, "scaleX", 1f, 2f);
ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(view, "scaleY", 1f, 2f);
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, "alpha", 1f, 0.5f);
animatorSet.playTogether(scaleXAnimator, scaleYAnimator, alphaAnimator);
animatorSet.setDuration(1000);
animatorSet.start();
在这个示例中,view对象会同时进行缩放和透明度变化的动画。通过调用animatorSet.playTogether()方法,将scaleXAnimator、scaleYAnimator和alphaAnimator同时添加到AnimatorSet中。然后设置动画的持续时间为1000毫秒,并调用animatorSet.start()方法来开始动画。这样,这三个动画就会同时运行。
原文地址: http://www.cveoy.top/t/topic/jgQe 著作权归作者所有。请勿转载和采集!