其他的Andr​​oid后

其他的Andr​​oid后

本文介绍了其他的Andr​​oid后,动画1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView 2 TranslateAnimations,我希望他们能够执行一个其他后。然而,通过使用下面的code,只有第二个被执行

我该如何解决这个问题?

  TranslateAnimation动画=新TranslateAnimation(
    Animation.ABSOLUTE,0.0,Animation.ABSOLUTE,0.0,
    Animation.ABSOLUTE,0.0,Animation.ABSOLUTE,-150.0f);
animation.setDuration(200);
wave.startAnimation(动画);

TranslateAnimation动画1 =新TranslateAnimation(
    Animation.ABSOLUTE,0.0,Animation.ABSOLUTE,0.0,
    Animation.ABSOLUTE,150.0f,Animation.ABSOLUTE,0.0);
animation1.setDuration(200);
wave.startAnimation(动画1);
 

解决方案

编辑:安迪靴回答以下是更好的答案海事组织


只需设置你的第一个这样的,它会启动另外一个,曾经在动画完成:

  animation.setAnimationListener(新AnimationListener(){

        @覆盖
        公共无效onAnimationStart(动画动画){
            // TODO自动生成方法存根

        }

        @覆盖
        公共无效onAnimationRepeat(动画动画){
            // TODO自动生成方法存根

        }

        @覆盖
        公共无效onAnimationEnd(动画动画){
            wave.startAnimation(动画1);

        }
    });
 

编辑:只有你的第二个动画与你现在的code所执行的原因,是因为它覆盖了第一个动画的播放(两者实际上都玩过,但你只能看到最新一期开始)。如果你不喜欢我写的,他们将发挥顺序,而不是并行。

I have two TranslateAnimations on a TextView and I want them to execute one after other. However, by using the code below, only the second one is executed.

How can I solve this?

TranslateAnimation animation = new TranslateAnimation(
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f,
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, -150.0f);
animation.setDuration(200);
wave.startAnimation(animation);

TranslateAnimation animation1 = new TranslateAnimation(
    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f,
    Animation.ABSOLUTE, 150.0f, Animation.ABSOLUTE, 0.0f);
animation1.setDuration(200);
wave.startAnimation(animation1);
解决方案

EDIT: Andy Boots answer below is the better answer imo.


Just set your first one like this and it'll start the other one, once the animation finishes:

animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            wave.startAnimation(animation1);

        }
    });

edit: The reason only your second animation is executed with your current code, is because it overrides the playing of the first animation (both actually are played, but you only see the latest one to start). If you do like I wrote, they will play sequentially instead of in parallel.

这篇关于其他的Andr​​oid后,动画1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:28