可能重复:
How to use fade in and fade out effect with an image using Transition, android
http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm
我看过这个链接。它通过使用淡入和淡出效果显示图像。我怎么能以编程方式执行此操作?
答案 0 :(得分:2)
创建两个Animation
Animation fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
Animation fadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
设置持续时间
fadeOutAnimation.setDuration(1000);
fadeInAnimation.setDuration(1000);
设置监听器 - 当淡出动画完成替换图像
时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
}
});
ImageView.startAnimation(fadeOutAnimation);