如何链接 rotationAnimation?

我想旋转一个 ImageView。但我想从 0 旋转到 45 到 -45,然后返回 0 来总结我的目标。


我尝试创建 4rotationAnimation并将它们与AnimatorSet.


这是我的代码:


    rotate = new RotateAnimation(0, 45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

    rotate.setDuration(1000);

    rotate.setInterpolator(new LinearInterpolator());

    rotate1 = new RotateAnimation(45, -45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

    rotate1.setDuration(1000);

    rotate1.setInterpolator(new LinearInterpolator());

    rotate2 = new RotateAnimation(-45, 45, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

    rotate2.setDuration(1000);

    rotate2.setInterpolator(new LinearInterpolator());

    rotate3 = new RotateAnimation(45, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

    rotate3.setDuration(1000);

    rotate3.setInterpolator(new LinearInterpolator());

    setAnim= new AnimationSet(true);

    setAnim.addAnimation(rotate);

    setAnim.addAnimation(rotate1);

    setAnim.addAnimation(rotate2);

    setAnim.addAnimation(rotate3);

img.startAnimation(setAnim);

目前图像突然没有旋转到 45° 并返回到 0°。


凤凰求蛊
浏览 93回答 2
2回答

青春有我

您可以使用AnimationListener例子yourFirstAnim.setAnimationListener(new AnimationListener() {    @Override    public void onAnimationStart(Animation animation) {    }    @Override    public void onAnimationRepeat(Animation animation) {    }    @Override    public void onAnimationEnd(Animation animation) {      doYourNextAnim()    }  });或者更简单的方法,使用AnimatorSet()AnimatorSet as = new AnimatorSet();as.playSequentially(yourFirstAnim,                     yourSecondAnim,                    ..,                    ...);as.setDuration(YOUR_DURATION);as.start();更新 为了避免回调地狱,我们可以使用StartDelayimgAvatar1.animate()        .alpha(1f)        .setDuration(YOUR_DURATION)        .start()    imgAvatar2.animate()        .alpha(1f)        .setStartDelay(YOUR_DURATION * 1)        .setDuration(YOUR_DURATION)        .start()     imgAvatar3.animate()        .alpha(1f)        .setStartDelay(YOUR_DURATION * 2)        .setDuration(YOUR_DURATION)        .start() 

月关宝盒

您正在使用您的AnimationSet().问题可能出在参数上fillAfter。setFillAfter(true)在你的动画上使用rotate,所以动画参数在动画之后应用。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java