淡入淡出动画会使视图闪烁

时间:2015-02-19 08:12:56

标签: android animation

我想让三个文本视图一个接一个地淡出。我试图在完成第一次后开始动画等等。但它不适合我。请帮忙

            text_1.setVisibility(View.INVISIBLE);
            text_2.setVisibility(View.INVISIBLE);
            text_3.setVisibility(View.INVISIBLE);

private void fadingAnimation() {
        Animation fadeIn = new AlphaAnimation(0, 1);
        fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
        fadeIn.setDuration(2000);
        AnimationSet animation1 = new AnimationSet(false); //change to false
        final AnimationSet animation2 = new AnimationSet(false); //change to false
        final AnimationSet animation3 = new AnimationSet(false); //change to false
        animation1.addAnimation(fadeIn);
        animation1.setAnimationListener(new Animation.AnimationListener(){
            @Override
            public void onAnimationStart(Animation arg0) {
            }           
            @Override
            public void onAnimationRepeat(Animation arg0) {
            }           
            @Override
            public void onAnimationEnd(Animation arg0) {
                text_1.setVisibility(View.VISIBLE);
                text_2.startAnimation(animation2);
            }
        });


        text_1.startAnimation(animation1);

  }

1 个答案:

答案 0 :(得分:0)

将您的方法更改为

private void fadingAnimation() {
        Animation fadeIn = new AlphaAnimation(0, 1);
        fadeIn.setInterpolator(new DecelerateInterpolator()); //add this
        fadeIn.setDuration(2000);
        AnimationSet animation1 = new AnimationSet(false); //change to false
        final AnimationSet animation2 = new AnimationSet(false); //change to false
        final AnimationSet animation3 = new AnimationSet(false); //change to false
        animation1.addAnimation(fadeIn);
        animation1.setAnimationListener(new Animation.AnimationListener(){
            @Override
            public void onAnimationStart(Animation arg0) {
            }           
            @Override
            public void onAnimationRepeat(Animation arg0) {
            }           
            @Override
            public void onAnimationEnd(Animation arg0) {
                text_1.setVisibility(View.VISIBLE);
                text_2.startAnimation(animation2);
            }
        });

 animation2.addAnimation(fadeIn);
        animation2.setAnimationListener(new Animation.AnimationListener(){
            @Override
            public void onAnimationStart(Animation arg0) {
            }           
            @Override
            public void onAnimationRepeat(Animation arg0) {
            }           
            @Override
            public void onAnimationEnd(Animation arg0) {
                text_2.setVisibility(View.VISIBLE);
                text_3.startAnimation(animation3);
            }
        });


animation3.addAnimation(fadeIn);
        animation3.setAnimationListener(new Animation.AnimationListener(){
            @Override
            public void onAnimationStart(Animation arg0) {
            }           
            @Override
            public void onAnimationRepeat(Animation arg0) {
            }           
            @Override
            public void onAnimationEnd(Animation arg0) {
                 text_3.setVisibility(View.VISIBLE);

            }
        });


        text_1.startAnimation(animation1);

  }