如何通过在Android上以编程方式使用Transitions来淡入和淡出图像视图?

时间:2012-09-05 09:01:06

标签: android image fadein transition fadeout

  

可能重复:
  How to use fade in and fade out effect with an image using Transition, android

http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm

我看过这个链接。它通过使用淡入和淡出效果显示图像。我怎么能以编程方式执行此操作?

1 个答案:

答案 0 :(得分:2)

  1. 创建两个Animation

    Animation fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);  
    Animation fadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
    
  2. 设置持续时间

    fadeOutAnimation.setDuration(1000);
    fadeInAnimation.setDuration(1000);
    
  3. 设置监听器 - 当淡出动画完成替换图像

    fadeOutAnimation.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) {
                //here switch the images !
                //and the begin the second animation FadeIn 
            }
        });
    
  4. ImageView.startAnimation(fadeOutAnimation);